我try 了很多方法来通过jQuery或JavaScript检测浏览器关闭事件.但是,不幸的是,我还没能察觉到这一关头.onbeforeunload
和onunload
方法也不起作用.
How do I detect the window close
, unload
, or beforeunload
events?
我try 了很多方法来通过jQuery或JavaScript检测浏览器关闭事件.但是,不幸的是,我还没能察觉到这一关头.onbeforeunload
和onunload
方法也不起作用.
How do I detect the window close
, unload
, or beforeunload
events?
你试过这个密码吗?
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(function () {
$("a").not('#lnkLogOut').click(function () {
window.onbeforeunload = null;
});
$(".btn").click(function () {
window.onbeforeunload = null;
});
});
The second function is optional to avoid prompting while clicking on #lnkLogOut
and .btn
elements.
还有一件事,自定义提示在Firefox中不起作用(即使在最新版本中也是如此).欲了解更多详细信息,请访问this线程.