8 February 2013

How to display message before closing the page or moving to another page. Don't use this to annoy people. Sometimes this functionality is still useful, for an example if you have some sort of unsaved process going on in browser.

Source code viewer
  1. // JavaScript
  2. window.onbeforeunload = function(){
  3. return 'Are you sure you want to leave the page?';
  4. };
  5.  
  6. // jQuery
  7. $(window).bind('beforeunload', function(){
  8. return 'Are you sure you want to leave the page?';
  9. });
Programming Language: Javascript