In the browser. This is a beforeunload event handler that returns custom dialog text that is only the middle of the three paragraphs — the other two paragraphs, as well as the button text, cannot be changed or otherwise changed.
window.onbeforeunload = function(){ return 'Testing...' } // OR var unloadListener = function(){ return 'Testing...' }; window.addEventListener('beforeunload', unloadListener);
A dialog box will appear
Are you sure you want to navigate away from this page? Testing... Press OK to continue, or Cancel to stay on the current page.
This can be reversed by setting the handler to zero
window.onbeforeunload = null; // OR window.removeEventListener('beforeunload', unloadListener);
Peter Bailey Aug 17 '09 at 17:19 2009-08-17 17:19
source share