javascript - Is there a cross-browser onload event when clicking the back button? -
for major browsers (except ie), javascript onload
event doesn’t fire when page loads result of button operation — it fires when page first loaded.
can point me @ sample cross-browser code (firefox, opera, safari, ie, …) solves problem? i’m familiar firefox’s pageshow
event unfortunately neither opera nor safari implement this.
guys, found jquery has 1 effect: page reloaded when button pressed. has nothing "ready".
how work? well, jquery adds onunload event listener.
// http://code.jquery.com/jquery-latest.js jquery(window).bind("unload", function() { // ...
by default, nothing. somehow seems trigger reload in safari, opera , mozilla -- no matter event handler contains.
[edit(nickolay): here's why works way: webkit.org, developer.mozilla.org. please read articles (or summary in separate answer below) , consider whether really need , make page load slower users.]
can't believe it? try this:
<body onunload=""><!-- trick --> <script type="text/javascript"> alert('first load / reload'); window.onload = function(){alert('onload')}; </script> <a href="http://stackoverflow.com">click me, press button</a> </body>
you see similar results when using jquery.
you may want compare 1 without onunload
<body><!-- not reload on button --> <script type="text/javascript"> alert('first load / reload'); window.onload = function(){alert('onload')}; </script> <a href="http://stackoverflow.com">click me, press button</a> </body>
Comments
Post a Comment