我使用以下代码在用户关闭页面时提示消息:
window.onbeforeunload = function(e) {
e = e ? e : window.event;
if(e) {
e.returnValue = '';
}
return '';
}
我想避免当用户单击页面上的特殊链接(例如 id="myid"
)时显示此消息的提示。是否可以?我尝试过这样的:
var source = e.target || e.srcElement;
console.log(source);
但是source
为null
,是否可以绑定(bind)事件并使用onbeforeunload
检查它?
“e”属性是什么?我如何查看这个“对象”?有什么想法吗?
最佳答案
如果链接被点击,则解除事件绑定(bind),然后重定向
window.onbeforeunload = null;
关于javascript - 使用 onbeforeunload 绑定(bind)事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36616349/