【发布时间】:2010-12-20 15:35:51
【问题描述】:
我有一个系统,我想与用户核实,一旦设置了脏标志,他们是否确定要离开页面。
我正在使用以下代码 - 在 FireFox 中,我可以通过 FireBug 查看页面源,并且标签中正确插入了 onbeforeunload 属性。
在 Chrome 和 FireFox 中,这不会发生,我可以在没有任何警告的情况下离开页面。更新 body 标签的 jQuery 行肯定正在执行,只是没有执行。
if ($("body").attr('onbeforeunload') == null) {
if (window.event) {
// IE and Chrome use this
$("body").attr('onbeforeunload', 'CatchLeavePage(event)');
}
else {
// Firefox uses this
$("body").attr('onbeforeunload', 'return false;CatchLeavePage(event)');
}
}
有什么想法可以从这里开始吗?
【问题讨论】:
-
我可以使用 $("body").css("margin", "50px");和 $("body").attr("test", "hello");看来我现在无法设置 onbeforeunload 属性...
标签: javascript jquery google-chrome onbeforeunload