Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS中的确认弹出窗口_Javascript_Dom Events_Onbeforeunload - Fatal编程技术网

Javascript JS中的确认弹出窗口

Javascript JS中的确认弹出窗口,javascript,dom-events,onbeforeunload,Javascript,Dom Events,Onbeforeunload,我正在考虑用JavaScript制作一个确认菜单,根据您选择是或否,它将在其中运行一组代码 现在,我希望它发生在窗口上。onbeforeunload事件,但只有当个人按下“yes”时,我才希望其余的代码工作。如果他们按“否”,我希望立即取消窗口.onbeforeuload。我想知道这是否有可能以及如何实现。这是我到目前为止所拥有的。我之所以希望这样做,是因为当我运行脚本时,返回时弹出窗口会出现,但在有人选择留下或离开之前。click()功能将启动擦除信息。我想要。单击()在某人按下返回键“是”后

我正在考虑用JavaScript制作一个确认菜单,根据您选择是或否,它将在其中运行一组代码

现在,我希望它发生在
窗口上。onbeforeunload
事件,但只有当个人按下“yes”时,我才希望其余的代码工作。如果他们按“否”,我希望立即取消
窗口.onbeforeuload
。我想知道这是否有可能以及如何实现。这是我到目前为止所拥有的。我之所以希望这样做,是因为当我运行脚本时,返回时弹出窗口会出现,但在有人选择留下或离开之前。
click()功能将启动擦除信息。我想要
。单击()在某人按下返回键“是”后启动,并且仅当他们按下“是”时启动


为什么不直接使用?

为什么不直接使用?

我刚刚注意到,但它能与IE、FF、Chrome和Safari一起使用吗?我该如何将其融入脚本?删除您的脚本,它似乎完全无用Sokay,然后呢?我只是想知道onbeforeunload方法是否仍然有效。是的。几乎所有的
onEVENT
方法都以相同的方式工作:如果该方法返回
false
,则该操作将被取消,否则它将继续正常处理事件。感谢您告诉我这将非常有帮助。:-)我刚刚注意到了这一点,但它会与IE、FF、Chrome和Safari一起工作吗?我该如何将其融入脚本?删除您的脚本,它似乎完全无用Sokay,然后呢?我只是想知道onbeforeunload方法是否仍然有效。是的。几乎所有的
onEVENT
方法都以相同的方式工作:如果该方法返回
false
,则该操作将被取消,否则它将继续正常处理事件。感谢您告诉我这将非常有帮助。:-)
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();
});