Execute function before refresh
Solution 1:
window.onbeforeunload = function(event)
{
return confirm("Confirm refresh");
};
Solution 2:
$(window).bind('beforeunload', function(){
return '>>>>>Before You Go<<<<<<<< \n Your custom message go here';
});
Source: http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/
Demo: http://www.mkyong.com/wp-content/uploads/jQuery/jQuery-stop-page-from-exit.html
Solution 3:
$(window).bind("beforeunload", function(){
return confirm("Do you really want to refresh?");
});
Solution 4:
the jQuery related event is:
$( window ).on('unload', function( event ) {
console.log('Handler for `unload` called.');
});
Works great for me.