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;
};

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

Leave a Reply