在我的HTML页面上,当用户单击/按F5按钮时页面刷新,但在刷新之前我想执行一个函数或一个简单的警报。
用户可以点击刷新按钮,按F5或Ctrl + R.
使用核心JavaScript,jQuery或YUI。
window.onbeforeunload = function(event)
{
return confirm("Confirm refresh");
};
$(window).bind('beforeunload', function(){
return '>>>>>Before You Go<<<<<<<< \n Your custom message go here';
});
资料来源:http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/
但是:ぁzxswい
jQuery相关事件是:
$(window).bind("beforeunload", function(){
return confirm("Do you really want to refresh?");
});
对我来说很棒。