关闭浏览器窗口之前的jQuery对话框 [英] JQuery dialog box before closing browser window
问题描述
我从其他帖子中了解到,解决此问题的唯一方法是通过无法编辑的浏览器对话框.我遇到的问题是,无论我如何离开页面,盒子都会出现.该页面上有一个保存和删除按钮,这是退出该页面的正确方法,我不希望为他们显示对话框.
I understand from other posts that the only way to handle this is through a browser dialogue box that can't be edited. What I am having a problem with is that box appearers no matter how I leave the page. The page has a save and delete button that are the correct ways to leave the page and I don't want the dialogue box to appear for them.
这是我拥有的jQuery
Here is the JQuery I have
$(document).ready(function(){
//save or delete
window.onbeforeunload = function() {
var message = 'You have unsaved changes, please stay and save or delete them.';
return message;
}
});
以及保存和删除"按钮是:
and the save and delete button are:
<a id='savenewscopesheet' class='taskbutton'>Save</a>
<a id='deletenewscopesheet' class='taskbutton'>Delete</a>
我正在使用更多的JQuery来处理其功能,因此它们没有href.
I am using more JQuery to handle their function hence they don't have an href.
推荐答案
更新了代码
$(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/
这篇关于关闭浏览器窗口之前的jQuery对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!