gatejs said on 26/04/2006 12:16 PM AEST:
In IE. If you use the back button,
the resulting page will execute the javascript in the page again:
In Firefox, whatever value a variable had is kept when you go back to
it:
var i=0;
// after some interaction with this page, i=4
visit some link
press the back button.
IE: i=0
Firefox: i=4
IE will also execute a body onload event (Firefox will not).
Any way around this (I want the firefox behavior in IE.)
Store the value somewhere other than a global variable. It seems to me
that IE is correct (or at least exhibits the expected behaviour), I
would expect the window object and all its properties to be destroyed
when the user navigates away from the page.
Anyhow, the following example stores the value in a hidden input, you
may want to use a cookie depending on whether all browsers retain form
values when navigating back to the page or not (I haven't tested too
widely):
<script type="text/javascript">
function addOne(){
var el = document.getElementById('store_x');
el.value = +el.value + 1;
return el.value;
}
</script>
<button onclick="alert('x is now: ' + addOne());">Add one</button>
<a href="http://www-internal.qdot.qld.gov.au/">Home</a>
<input type="hidden" id="store_x" value="0">
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>