var leaveFlag = 0;//value 0 is leave page show warn alert
function returnValue(){
if (leaveFlag == 0) {
var after_i = $("#invitees").val();
if (before_i != after_i) {
return "您的信息尚未保存.";
} else {
window.onbeforeunload = null;
}
}
};
//for browsers bind event
function leavePageVerify() {
if (window.addEventListener) { // all browsers except IE before version 9
window.addEventListener("beforeunload", OnBeforeUnLoad, false);
} else {
if (window.attachEvent) { // IE before version 9
window.attachEvent("onbeforeunload", OnBeforeUnLoad);
}
}
}
//chrome,ie9
function OnBeforeUnLoad() {
return returnValue();
}
//ff,ie8.ie7
window.onbeforeunload = function() {
return returnValue();
};
//upload
leavePageVerify();
在页面中,只要确认leaveFlag 的值就可以,不等于0就不会弹窗。