window.location & cookies?

C

changed

I have an application that works almost all of the time but there is an
inconsistent error with some browsers (some Mac, some PC). It seems that
the cookie won't get written before the redirect. If I turn on cookie
prompting my computer will stall just after this cookie is written (if it's
even written) *MOST* of the time.

setCookie("FC2", escape(escape(getCookie("FC"))), "", "/",
".lacs.utexas.edu", false);
window.location = "http://www.lacs.utexas.edu/logon.asp?step=2";

I can't use Server-Side Scripting, as JavaScript is necessary to write the
cookie (ASP and the server that writes the original cookie I'm using don't
agree about URL encoding). Even the ASP redirect won't work once the
JavaScript has been written to the client.

Is there a better solution than window.location or can I stick the
window.location further down in the code, perhaps giving the client time to
finish writing the cookie? Do you think this is even the problem?

Sorry if this doesn't make sense, this has been a frustrating problem for
the past week.
 
C

changed

setCookie("COOKIE", VALUE, "", "/", ".domain.com", false);

window.location = "http://www.domain.com/logon.asp?step=2";

Okay, I've made some progress in tracking down the problem but I don't have
a good solution. It seems that the cookie isn't populating on slower
machines before the redirect takes place (and thus the cookie never
populates?).

If I move the window.location statement further down it greatly increases
the chance of success.

If I get rid of the window.location statement and use an HREF, it works
100%.

How can I use a JavaScript redirect and maintain the 100% functionality
rate?

THANKS!!!
 
K

kaeli

How can I use a JavaScript redirect and maintain the 100% functionality
rate?

In a while (true) loop, keep trying to read the cookie. Once you can
read it, break out, then redirect.

-------------------------------------------------
~kaeli~
Hey, if you got it flaunt it! If you don't, stare
at someone who does. Just don't lick the TV screen,
it leaves streaks.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
C

changed

kaeli said:
In a while (true) loop, keep trying to read the cookie. Once you can
read it, break out, then redirect.

I think I found the problem. It was a timing issue, but it wasn't strictly
JavaScript. It does not appear wise to write cookies with ASP and
JavaScript in the same page request if those cookies are to be used
immediately afterwards. Something like that anyway... :)
 
K

kaeli

I think I found the problem. It was a timing issue, but it wasn't strictly
JavaScript. It does not appear wise to write cookies with ASP and
JavaScript in the same page request if those cookies are to be used
immediately afterwards. Something like that anyway... :)

Oh, no, it isn't. Server-side script cookies (ASP, JSP, ColdFusion) are
written via the headers, then stored a short time later if they are not
session cookies (i.e. they must be given an expiration date). In fact,
if you write the cookies via server-side script, then use a javascript
redirect that doesn't pass the headers, like location.replace(), you'll
lose the server-side cookies.
Javascript writes cookies immediately to the user's cookie area.
I've had problems combining the two before as well.

-------------------------------------------------
~kaeli~
Hey, if you got it flaunt it! If you don't, stare
at someone who does. Just don't lick the TV screen,
it leaves streaks.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,091
Messages
2,570,604
Members
47,223
Latest member
smithjens316

Latest Threads

Top