我有一个系统,如果他们确定他们想要在设置脏标志后离开页面,我想与用户核实.
我正在使用以下代码 - 在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)');
}
}
Run Code Online (Sandbox Code Playgroud)
有什么想法从这里开始?