back button and onload event

S

sunilp

Consider this scenario..
I m on page "1.html" in IE(6) and click on href which takes me to
"2.html".
I press browser back button. Then "onload" method of 1.html is fired.

onload is not fired on back button in Firefox but IE does.

I want to distinguish between first load of the page and false "onload"
fired by back button.
How do i do this?

~Sunil
 
V

Vincent van Beveren

I want to distinguish between first load of the page and false "onload"
fired by back button.

You could use the history.previous or history.next field to check what
page came before and after yours.

Greetings,
Vincent
 
B

Bart Van der Donck

Vincent said:
You could use the history.previous or history.next field to check what
page came before and after yours.

"if" a page (you can't know which one)
 
R

Richard Cornford

Vincent said:
You could use the history.previous or history.next field
to check what page came before and after yours.

Not all browsers provide - history.previous/next - properties, but those
that do tend to throw exceptions if you try to read them with code
running on a public web site (as that would be a privacy/security
violation).

Richard.
 
G

goulart

probably the easiest would be to use a cookie.

window.onload = function () {

if (document.cookie && document.cookie.indexOf("loaded=true") >= 0)
return;

document.cookie = "loaded=true";

}
 
R

Randy Webb

sunilp said the following on 7/13/2006 3:09 AM:
Consider this scenario..
I m on page "1.html" in IE(6) and click on href which takes me to
"2.html".
I press browser back button. Then "onload" method of 1.html is fired.

onload is not fired on back button in Firefox but IE does.

I want to distinguish between first load of the page and false "onload"
fired by back button.
How do i do this?

You can't.
 
R

Randy Webb

Vincent van Beveren said the following on 7/13/2006 3:41 AM:
You could use the history.previous or history.next field to check what
page came before and after yours.

Oh? Do you have sample code that shows how to get entries in the history
trail?
 
R

Randy Webb

(e-mail address removed) said the following on 7/13/2006 10:38 AM:

Question: What's the easiest way to spot a Google Groups user?
Answer: I would tell you but I would have to quote it.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

probably the easiest would be to use a cookie.

No, that is not "probably the easiest" way.
window.onload = function () {

if (document.cookie && document.cookie.indexOf("loaded=true") >= 0)
return;

document.cookie = "loaded=true";

}

Did you test it?
P.S. Disable cookies and test your code......
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top