Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > cookies, onLoad and IE v Firefox

Reply
Thread Tools

cookies, onLoad and IE v Firefox

 
 
Clive Backham
Guest
Posts: n/a
 
      04-09-2008
For reasons I won't bore people with, I'm modifying a session cookie
inside an event handler and then analysing the cookie in the onLoad
page handler when the user returns to the same page having navigated
away from it in the meantime. My problem is that the behaviour is
different in IE and Firefox.

I've tried to pare this down to the simpest page that demonstrates the
issue:

<html>
<head>
<script type="text/javascript">
function init()
{
showcookie();
}
function showcookie()
{
document.getElementById("log").value = document.cookie;
}
function modifycookie()
{
document.cookie = "timestamp=" + new Date().toString();
}
</script>
</head>
<body onload="init();">
<input name=log id=log size=100><br>
<input type=button value="show cookie" onclick="showcookie();"><br>
<input type=button value="modify cookie" onclick="modifycookie();">
</body>
</html>

Here's the sequence of events that show the problem:
1. Load the page.
2. Click the "modify cookie" button.
3. Hit the Back button, then the Forward button.
4. Note the value of the "log" field.
5. Click the "show cookie" button and note again the value of the
"log" field.

I would expect the values noted in steps 4 and 5 to be the same, and
in IE they are. But in Firefox (and Opera) they are not.

If we add this extra action between steps 2 and 3:
2A. Click the "show cookie" button.

Then Firefox and Opera behave as expected: after a Back and Forward,
the "log" field shows the updated value.

It's almost as if Firefox and Opera are not setting the value of
document.cookie until after the onLoad handler has completed.

I must be missing something fundamental here.
 
Reply With Quote
 
 
 
 
Ed
Guest
Posts: n/a
 
      04-10-2008
On Apr 9, 6:47*am, Clive Backham <(E-Mail Removed)> wrote:
> 3. Hit the Back button, then the Forward button.


The onload handler is probably not getting called here in Firefox/
Opera.

> It's almost as if Firefox and Opera are not setting the value of
> document.cookie until after the onLoad handler has completed.


The value is from the back-forward cache. See:

http://developer.mozilla.org/en/docs...ox_1.5_caching

 
Reply With Quote
 
 
 
 
Clive Backham
Guest
Posts: n/a
 
      04-10-2008
On 10 Apr, 05:45, Ed <(E-Mail Removed)> wrote:
> On Apr 9, 6:47*am, Clive Backham <(E-Mail Removed)> wrote:
>
> > 3. Hit the Back button, then the Forward button.

>
> The onload handler is probably not getting called here in Firefox/
> Opera.


So is that "correct" in a formal sense? Should browsers be allowed to
just ignore the onLoad event?

> The value is from the back-forward cache. *See:
>
> *http://developer.mozilla.org/en/docs...ox_1.5_caching


Thanks for the link. I'll experiment with the onPageShow event - it
looks like it should do what I need.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
onload -->* no onload marco Javascript 7 06-24-2006 08:39 PM
Firefox and <body onload=.. > firing after page is rendered usenet@ctoxyeb.com Javascript 3 08-16-2005 10:51 PM
Why doesn't frameset onload event get called when each of the frames has an onload? adnanx82@gmail.com Javascript 5 05-15-2005 01:58 PM
base.OnLoad called, OnLoad not executed Fabio R. ASP .Net 0 03-25-2005 01:21 PM
window.onload and body.onload differences David Otton Javascript 2 11-04-2004 04:34 PM



Advertisments