0

可能重复:
如何使用 javascript 删除卸载事件提示

我正在开发一个运行 onbeforeunload 和 onunload 的 Javascript,现在脚本通常运行良好,但是在 IE 和 Firefox 上,它会运行一个提示,询问您是否要离开,无论您选择什么选择,其余代码都会执行仍然。现在在 Chrome 和 Safari 上它没有这个问题。我试图弄清楚为什么 IE 和 Firefox 会这样做,并尝试将其从一起显示提示框中删除。如果有帮助,这是我的代码:

var leave_message = document.getElementById("kioskform:broswerCloseSubmit");
var leave_safari = document.getElementById("kioskform:broswerCloseSafari");

function goodbye(e) {
    if (!validNavigation) {
        if (dont_confirm_leave!==1) {
            leave_message.click();
            if(!e) e = window.event;

            //e.cancelBubble is supported by IE - this will kill the bubbling process.
            e.cancelBubble = true;
            e.returnValue = leave_message.click();

            //e.stopPropagation works in Firefox.
            if (e.stopPropagation) {
                e.stopPropagation();
                e.preventDefault();
            }

            //return works for Chrome and Safari
            //canceling this makes IE work well but not make Safari work at all.
            leave_safari.click();
        }
    }
}

window.onbeforeunload=goodbye;
window.onunload=leave; 

function leave() {
    document.getElementById('kioskform:broswerCloseSubmit').click();           
}
4

0 回答 0