我正在开发一个运行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();
}