[ACCEPTED]-Alerts when navigating away from a web page-alerts

Accepted answer
Score: 86

By the browser. It's the beforeunload event handler 7 that returns the customized text of the 6 dialog, which is only the middle of the 5 three paragraphs - the other two paragraphs 4 as well as the text of the buttons cannot 3 be customized or otherwise changed.

window.onbeforeunload = function(){ return 'Testing...' }

// OR

var unloadListener = function(){ return 'Testing...' };
window.addEventListener('beforeunload', unloadListener);

Will 2 yield a dialog that says

Are you sure you want to navigate away from this page?

Testing...

Press OK to continue, or Cancel to stay on the current page.

You can nullify 1 this by setting the handler to null

window.onbeforeunload = null;

// OR

window.removeEventListener('beforeunload', unloadListener);

More Related questions