gpt4 book ai didi

javascript - JS 中的确认弹出窗口

转载 作者:行者123 更新时间:2023-11-28 02:41:42 25 4
gpt4 key购买 nike

我正在考虑在 JavaScript 中制作一个确认菜单,根据您选择"is"还是“否”,它将在其中运行一组代码。

现在我希望它发生在 window.onbeforeunload 事件上,但只有当个人按下“yes”时,我才希望其余代码起作用。如果他们按“否”,我希望彻底取消 window.onbeforeunload。我想知道这是否可能以及如何实现。这是我到目前为止所拥有的。我想要这个的原因是因为当我运行脚本时,弹出窗口会在返回时显示,但在有人选择留下或离开之前。 click(); 功能开始删除信息。我希望 .click(); 在有人按回车键“yes”后启动,并且只有当他们按“yes”时才启动。

var validNavigation = false;

function wireUpEvents() {

var dont_confirm_leave = 0;
var leave_message = document.getElementById("kioskform:broswerCloseSubmit");
var leave_safari = document.getElementById("kioskform:broswerCloseSafari");
function goodbye(e) {
if (!validNavigation) {
function disp_confirm()
{
var leaveMessage=confirm("Are you sure you want to leave")
if (leaveMessage==true)
{ if (dont_confirm_leave!==1) {
if(!e) e = window.event;
//for IE
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
leave_safari.click();
return '';

//add the code to delete the kiosk information here.
// this is what is to be done.
}
}

else
{
Alert("Returning to the page.")
}
}
window.onbeforeunload=goodbye;

// Attach the event keypress to exclude the F5 refresh
jQuery('document').bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});

// Attach the event click for all links in the page
jQuery("a").bind("click", function() {
validNavigation = true;
});

// Attach the event submit for all forms in the page
jQuery("form").bind("submit", function() {
validNavigation = true;
});

// Attach the event click for all inputs in the page
jQuery("input[type=submit]").bind("click", function() {
validNavigation = true;
});

}

// Wire up the events as soon as the DOM tree is ready
jQuery(document).ready(function() {
wireUpEvents();
});

最佳答案

为什么不直接使用 window.confirm

关于javascript - JS 中的确认弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12546190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com