是否可以实现与Javascript window.confirm()相同的功能当用户点击Web浏览器的关闭按钮或离开页面或重新加载页面时,带有jquery模式对话框的框。
//////javascript code//////
sessionStorage["isTrue"] = false;
$(".PassReqNotes,.datePassed1").change(function () {
sessionStorage["isTrue"]= true;
});
$(window).bind('beforeunload', function (event) {
event.preventDefault();
var sessionValue = sessionStorage["isTrue"].toLocaleString();
if (sessionValue == "true") {
isTrue = false;
sessionStorage["isTrue"] = null;
//return 'If you leave page, You may lose some changes';
return window.confirm = dialog();
}
});
function dialog(event) {
$("#dialog-confirmPassReq").removeClass('hide').dialog({
resizable: false,
modal: true,
title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-exclamation-triangle red'></i> Delete Photo?</h4></div>",
title_html: true,
buttons: [
{
html: "<i class='ace-icon fa fa-trash-o bigger-110'></i> ok",
"class": "btn btn-danger btn-xs btnDeleteActivityPhoto",
click: function () {
$(this).dialog("close");
return true;
}
},
{
html: "<i class='ace-icon fa fa-times bigger-110'></i> Cancel",
"class": "btn btn-xs",
"id": "btnClosePassReq",
click: function () {
$(this).dialog("close");
return false;
}
}
]
});
}
答案 0 :(得分:0)
window.onbeforeunload = function() {
//your code
};