473,396 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why does this behave this way?

I want to direct the user to a page (usermenu.html) if upon entering
index.html there is a cookie set on the user's machine. The 'login' cookie
contains the user's id (username).

I'm calling scripts on loading as:

<body onload="initIndex();killAll();setLogin('visitor'); ">

Where killAll kills any existing cookies and setLogin sets a cookie with a
given identifier. initIndex() is

function initIndex () {
lValue = getCookieValue('login');
if (!lValue) {return;}
l_array = lValue.split("}");
username = l_array[3];
if (username == 'visitor' || username == 'guest') {return;}
else {setLogin(username);
window.location = './usermenu.html';
}
}

What is happening that I don't understand is that if I enter the page with a
non-visitor or non-guest cookie it sets the login cookie with the username,
then returns to the onload= line, kills the new cookie, sets a 'visitor'
cookie, and then launches the usermenu with the window.location directive.

Why does it return to the onload= command string before redirecting via
window.location?

TIA for your assistance,

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info
Aug 14 '08 #1
2 1018
On Aug 14, 3:46*pm, Ed Jay <ed...@aes-intl.comwrote:
I want to direct the user to a page (usermenu.html) if upon entering
index.html there is a cookie set on the user's machine. The 'login' cookie
contains the user's id (username).

I'm calling scripts on loading as:

<body onload="initIndex();killAll();setLogin('visitor'); ">

Where killAll kills any existing cookies and setLogin sets a cookie with a
given identifier. initIndex() is

function initIndex () {
* lValue = getCookieValue('login');
* * if (!lValue) {return;}
* * l_array = lValue.split("}");
* * * username = l_array[3];
* * if (username == 'visitor' || username == 'guest') {return;}
* *else {setLogin(username);
* *window.location = './usermenu.html';
* }

}

What is happening that I don't understand is that if I enter the page with a
non-visitor or non-guest cookie it sets the login cookie with the username,
then returns to the onload= line, kills the new cookie, sets a 'visitor'
cookie, and then launches the usermenu with the window.location directive..

Why does it return to the onload= command string before redirecting via
window.location?

TIA for your assistance,

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.http://www.breastthermography.info
There is nothing in your script that requires it to stop at:
window.location = './usermenu.html';

It does not have to stop and wait for the action associated with this
assignment operation to complete. It just trucks on, as it should.

Why not rewrite the three functions you are calling when the page
loads into one function, and just use a couple of if/else statements
to sort things out the way you would like?
Aug 14 '08 #2
Doug Gunnoe wrote:
>On Aug 14, 3:46*pm, Ed Jay <ed...@aes-intl.comwrote:
>I want to direct the user to a page (usermenu.html) if upon entering
index.html there is a cookie set on the user's machine. The 'login' cookie
contains the user's id (username).

I'm calling scripts on loading as:

<body onload="initIndex();killAll();setLogin('visitor'); ">

Where killAll kills any existing cookies and setLogin sets a cookie with a
given identifier. initIndex() is

function initIndex () {
* lValue = getCookieValue('login');
* * if (!lValue) {return;}
* * l_array = lValue.split("}");
* * * username = l_array[3];
* * if (username == 'visitor' || username == 'guest') {return;}
* *else {setLogin(username);
* *window.location = './usermenu.html';
* }

}

What is happening that I don't understand is that if I enter the page with a
non-visitor or non-guest cookie it sets the login cookie with the username,
then returns to the onload= line, kills the new cookie, sets a 'visitor'
cookie, and then launches the usermenu with the window.location directive.

Why does it return to the onload= command string before redirecting via
window.location?

TIA for your assistance,

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.http://www.breastthermography.info

There is nothing in your script that requires it to stop at:
window.location = './usermenu.html';

It does not have to stop and wait for the action associated with this
assignment operation to complete. It just trucks on, as it should.

Why not rewrite the three functions you are calling when the page
loads into one function, and just use a couple of if/else statements
to sort things out the way you would like?
That's what I ended up doing. Thanks.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info
Aug 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Timothy Madden | last post by:
Hello If I say #define MASK 0x00F0 #define BIT_SET MASK #define MASK 0x000F than what value will BIT_SET macro expand to ? I mean the preprocessor does lasy evaluation or immediate...
16
by: bluekite2000 | last post by:
I want Matrix A(B) to create shallow copy of B but A=B to create deep copy of B. Is that bad design? Why and why not?
13
by: Andy Leszczynski | last post by:
wikipedia (http://en.wikipedia.org/wiki/Python_programming_language#Object-oriented_programming) says: """ Python's support for object oriented programming paradigm is vast. It supports...
3
by: Claudio Grondi | last post by:
Trying to understand the outcome of the recent thread (called later reference thread): "Speed quirk: redundant line gives six-fold speedup" I have put following piece of Python code together:...
2
by: Joe Fallon | last post by:
I have a Shared class with a New constructor that initializes some Shared properties. One of the steps involves a hit to the database. My tests show that when called by a WinForms app, the...
6
by: beerbal | last post by:
Hello, I am a bit confused as to how the following snippet would work? #include <iostream> class Foo { public: void doSomething()
1
by: Richard | last post by:
A menu page has a set of A tages in a UL The menu (in IE) will only get the hover visualization if the mouse rolls over underlined text. I want it to happen if the rollover occurs anywhere in...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
2
by: Nikhil.S.Ketkar | last post by:
Hi, How does the == operator for multimap in STL behave ? I was under the impression that this is supposed to properly compare multimaps for equality. It seems that what it actually does is just...
13
by: cmrhema | last post by:
Hi, Kindly go through the code below public partial class _Default : System.Web.UI.Page { public static int i = 0; protected void Page_Load(object sender, EventArgs e) { }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.