Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>UPDATE: I wrote this 5 years ago, browsers do different stuff now, you can still use this for testing your browser set, but your experience may vary from my old research.</em></p> <p>Experimenting using jQuery, because I'm lazy.</p> <p>Theoretically, preventing the default behavior should stop the event from doing whatever it is supposed to do. It doesn't work with the events in my example and has different results in different browsers. I put the Math.random() in to determine if the page has been reloaded or not. Because different browsers do different things, I highly recommend NOT using this in a production environment.</p> <pre><code>&lt;body&gt; &lt;p&gt;&lt;/p&gt; &lt;script type="text/javascript"&gt; $('p').append(Math.random()); $(window).bind({ beforeunload: function(ev) { ev.preventDefault(); }, unload: function(ev) { ev.preventDefault(); } }); &lt;/script&gt; &lt;/body&gt; </code></pre> <p>Using CTRL-R or F5 or Reload Button:</p> <ul> <li>Safari: Does nothing</li> <li>Chrome: Does nothing</li> <li>Opera 10 &amp; 11: Does nothing</li> <li>Firefox 7.x: Shows a special prompt with two buttons: <ul> <li>Stay on Page - Does not reload page</li> <li>Leave Page - Reloads the page</li> </ul></li> <li>IE7 &amp; IE8: Shows a prompt with two buttons: <ul> <li>OK - Reloads the page</li> <li>Cancel - Does not reload the page</li> </ul></li> <li>IE9: Shows a prompt with two buttons: <ul> <li>Leave this page - reloads</li> <li>Stay on this page - does not reload</li> </ul></li> </ul> <p><strong>Firefox Prompt (you can tell I tested it on a Mac)</strong></p> <p><img src="https://i.stack.imgur.com/dEk0c.png" alt="Firefox Prompt"></p> <p><strong>IE7 &amp; IE8 Prompt</strong></p> <p><img src="https://i.stack.imgur.com/4pqNW.png" alt="IE7 &amp; IE8 Prompt"></p> <p><strong>IE9 Prompt</strong></p> <p><img src="https://i.stack.imgur.com/7he3X.png" alt="IE9 Prompt"></p> <p>In closing:</p> <p>Yes, I did not test IE6, I deleted my VM which had it installed, I don't have a VM with IE10 beta installed, so you're out of luck on that too.</p> <p>You might also experiment with cancelBubble and stopPropagation or maybe return false; might reveal something useful. I'm down with Jordan's reply that you shouldn't be trying to override the defaults, so I'm concluding my experiment here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload