Execute function before refresh

╄→гoц情女王★ 提交于 2019-11-27 08:15:40
    window.onbeforeunload = function(event)
    {
        return confirm("Confirm refresh");
    };
$(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

$(window).bind("beforeunload", function(){
        return confirm("Do you really want to refresh?"); 
});
Roy Shoa

the jQuery related event is:

$( window ).on('unload', function( event ) {
    console.log('Handler for `unload` called.');
});

Works great for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!