OK, I feel like I am giving you a loaded gun, but in testing here, this appears to work out for Safari and IE. Opera and FF seem to ignore it, sort of, but don't appear to do anything really bad with it.
Both Safari Win 3 and IE 7, and presumably their earlier versions will at least activate a reload of the page to a unique URL (which presumably busts page caching) upon navigating to the page using the browser's back or forward button. Nothing should happen with a fresh page load navigated to in the normal manner. If the refresh button on the browser is hit, various things may happen, depending upon the browser. I have taken precautions to try to ensure though that, under no circumstances will an endless loop of reloading ensue. I may have missed something. If this does happen, use whatever utility you have on your computer to kill the browser instance - stop the browser even though it's busy (in windows that's called task manager).
Here's what you do. Be sure to do both things, otherwise something bad/weird, like a looping reload that you will need to recover from by killing the browser could more easily happen. Put this script in the head of the page:
Code:
<script type="text/javascript">
function testForBack(){
if(document.forms[0].elements[0].value=='later'){
document.forms[0].elements[0].value='first';
window.location.replace(window.location.href.replace(window.location.search,'')+'?reloaded='+new Date().getTime());
}
else
document.forms[0].elements[0].value='later';
}
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", testForBack, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", testForBack );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
testForBack();
};
}
else
window.onload = testForBack;
}
</script>
Put this markup immediately after the opening <body> tag:
HTML Code:
<form style="visibility:hidden;position:absolute;top:-1000px;left:-1000px;" action="#" onsubmit="return false;">
<input type="hidden" value="first">
</form>
Bookmarks