当用户尝试离开表单页面时,我有一条javascript消息提醒用户,以防他没有按照以下方式填写表单:
window.onbeforeunload = function (evt) {
if(window.nounloadcheck == true) return;
var message = 'Data you entered may not be saved';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
我在同一页面上也有一个链接,用于打开彩色模块模式,以便用户可以上传新照片。提交新照片后,颜色框模式将关闭并刷新主页面,以便用户可以看到他们上传的新照片。这是用于刷新主页的颜色框代码:
jQuery(document).ready(function(){
jQuery(".iframe").colorbox({iframe:true, width:"748px", height:"92%", onClosed:function(){ location.reload(true); } });
});
问题是当页面尝试重新加载时,会出现javascript警报。我试过了:
<form ... onSubmit='window.nounloadcheck = true; return true;'>
这个单词用于主页上表单的提交按钮。但它不适用于colorbox模式上的提交按钮。如何在关闭colorbox模式时阻止主页显示javascript警告?
答案 0 :(得分:1)
无法在onClosed
之前将其添加到location.reload
函数吗?
答案 1 :(得分:1)
您正在寻找:
<form ... onSubmit='window.onbeforeunload = null; return true;'>
这将在事件处理程序运行之前将其清除。