Thursday, January 10, 2013

How to alert user before leaving the page


onunload (or onbeforeunload) will prevent user from navigating to another page.

Use the below JavaScript code

window.onbeforeunload = function()

 return 'Are you sure you want to leave?'; 
};

Or with jQuery:

$(window).bind('beforeunload', function()
 return 'Are you sure you want to leave?'; 
});

No comments:
Write comments
Recommended Posts × +