关闭浏览器窗口之前的JQuery对话框
我从其他post中了解到,处理此问题的唯一方法是通过无法编辑的浏览器对话框。 无论我如何离开页面,我遇到的问题都是盒子出现者。 该页面有一个保存和删除按钮,这是离开页面的正确方法,我不希望为他们显示对话框。
这是我的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; } });
以及保存和删除按钮是:
Save Delete
我正在使用更多的JQuery来处理它们的function,因此它们没有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; } });
试试这个..