【问题标题】:JQuery dialog box before closing browser window关闭浏览器窗口之前的 JQuery 对话框
【发布时间】:2012-06-01 08:48:24
【问题描述】:

我从其他帖子中了解到,处理此问题的唯一方法是通过无法编辑的浏览器对话框。我遇到的问题是,无论我如何离开页面,该框都会出现。该页面有一个保存和删除按钮,这是离开页面的正确方法,我不希望为他们显示对话框。

这是我的 JQuery

$(document).ready(function(){
//save or delete
  window.onbeforeunload = function() {
              var message = 'You have unsaved changes, please stay and save or delete them.';
              return message;
          }
}); 

保存和删除按钮是:

  <a id='savenewscopesheet' class='taskbutton'>Save</a>
  <a id='deletenewscopesheet' class='taskbutton'>Delete</a>

我正在使用更多的 JQuery 来处理它们的功能,因此它们没有 href。

【问题讨论】:

    标签: jquery dialog popup window


    【解决方案1】:

    更新了代码

    $(document).ready(function(){
    //save or delete
    
    $('.taskbutton').click(function() {
    
        window.onbeforeunload = null;
    
        window.location='yourUrl'; //navigate to required page..
    
    });
    
    window.onbeforeunload = function() {
                  var message = 'You have unsaved changes, please stay and save or delete them.';
                  return message;
              }    
    
    
    
    }); 
    

    试试这个..

    http://jsfiddle.net/kabichill/px4ZU/

    【讨论】:

    • 这没有帮助。我只希望在不单击这两个按钮时出现消息。
    • 当你点击保存和删除按钮时应该会发生什么??简要你再次提问
    • 它应该只是加载新页面而不出现对话框
    • 这是一段很棒的代码!你甚至可以在这个函数中运行一个 ajax 调用来满足你的需要
    • 消息文本没有出现在 Firefox 中。
    猜你喜欢
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2011-02-18
    • 2010-10-13
    • 2020-11-21
    • 2014-10-14
    相关资源
    最近更新 更多