关闭浏览器窗口前的JQuery对话框

时间:2012-06-01 08:48:25

标签: jquery dialog popup window

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

这是我有的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。

1 个答案:

答案 0 :(得分:2)

更新了代码

$(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/

相关问题