I want to show a confirmation dialog if the user wants to leave the page with unsaved form data. What I have is:
window.onbeforeunload = function() {
if
With jQuery, you can set the same handlers. The code may defer based on your version.
function AnyFunction(e){ /**** your code *****/ };
$(function () {
$(window).bind('unload', function (e) { return AnyFunction(e); });
$(window).bind('beforeunload', function (e) { return AnyFunction(e); });
});
You can also change the confirm or alert function using plugins as bootbox.