How to make a confirmation prompt before leaving the page in javascript

To make a confirmation prompt before leaving the page in javascript you can use the following snippet.

Sample Javascript

window.onbeforeunload = function(){
	var msg = 'Do you really want to leave this page?';
        return msg;
};

Please Share us:
Please rate this snippet

2 thoughts on “How to make a confirmation prompt before leaving the page in javascript

Leave a Reply