Why does Firefox 5.0.1 not refresh this page when the back button is pressed?
<html>
<head>
<meta http-equiv="cache-control" content="no-cache">
<script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() { alert('ready'); });
$(window).load(function() { alert('load'); });
</script>
</head>
<body>
<form action="http://www.google.com" method="get">
<input name="q" type="text">
<input type="submit">
</form>
</body>
</html>
Steps to reproduce:
Update:
This will to force firefox to reload the page:
$(window).unload(function() {});
But, I ended up using this:
window.addEventListener('pageshow', function() {alert('pageshow'); }, false);
Why does Firefox 5.0.1 not refresh this page when the back button is pressed?
Because it doesn't need to.
When you go "back" in Firefox and Firefox can load the page entirely from the back button buffer, then what you are going back to is not to a fresh page but to the page in the exact state you left it before as if nothing had happened in between, and that includes the state of all your Javascript code and variables. As far as your script (and jQuery) is concerned, ready() has already fired. jQuery will not fire it a second time if it's already fired.
What you probably want is to listen to the 'pageshow' event, which Firefox fires when the page is re-loaded from the buffer, even if its state is fully preserved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With