[英]jquery confirm box when user hit the close button in web browser's window
Is it possible to implement the same functionality as Javascript window.confirm() Box with jquery Modal Dialog Box when user hits the Web Browser's close button or leave the page or reload the page. 当用户单击Web浏览器的关闭按钮或离开页面或重新加载页面时,是否可以实现与Javascript window.confirm()Box相同的功能。
//////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;
}
}
]
});
}
window.onbeforeunload = function() {
//your code
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.