[英]Capture Browser close event without refresh event
我有与浏览器关闭事件有关的问题。
如何捕获浏览器关闭事件而没有刷新事件。
提前致谢。
使用window.onbeforeunload
但是当您重新加载浏览器或通过单击链接移动到其他页面时,也会触发该事件。
window.onbeforeunload = function(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
};
注意: window.onbeforeunload
不适用于Android以外的触摸设备。
试试这个
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('#LogOut').click(function () {
window.onbeforeunload = null;
});
$(".btn").click(function () {
window.onbeforeunload = null;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.