我试图让 window.confirm 使用我正在使用的脚本,但它似乎不想工作。发生的情况是,如果该人按下取消它仍然运行代码,可悲的是现在我编写代码的方式弹出框甚至不会出现在 chrome 中。不知道为什么虽然我可以删除 window.confirm 方法并且它仍然会显示一个弹出框,但它只会运行脚本,无论您做出哪个选择。这是代码,谢谢您的帮助。
var validNavigation = false;
function wireUpEvents() {
var dont_confirm_leave = 0; to be able to leave withou confirmation
var leave_message = 'Leaving the page will terminate your Self-Service or Kiosk session.';
function goodbye(e) {
if (!validNavigation)
function goodbye() = {
var x = window.confirm("Leaving the page will terminate your Self-Service or Kiosk session.")
if (x)
{
window.onunload=leave;
}
else {
return "" ;
}
}}
function leave() {
if (!validNavigation) {
killSession();
}
}
//set event handlers for the onbeforeunload and onunloan events
window.onbeforeunload=goodbye;
//window.onunload=leave;
}
// Wire up the events as soon as the DOM tree is ready
jQuery(document).ready(function() {
wireUpEvents();
});