关闭页面时,弹出JS提示框提示是否关闭
JQUERY写法:
$(window).bind('beforeunload', function (e) {
var isEdit = '<%=FormMastPage.ViewMode%>';
if (window.is_confirm !== false && isEdit == Enumerator.ItemViewMode.AllEdit) {
var message = '<%=this.GetRes("Msg_CheckPageEditMode")%>';
e.returnValue = message;
}
})
.bind('mouseover mouseleave', function (event) {
is_confirm = event.type == 'mouseleave';
});
JAVASCRIPT写法:
window.onbeforeunload = function (event) {
var event = event || window.event;
// 兼容IE8和Firefox 4之前的版本
if (event) {
event.returnValue = "确定要关闭窗口吗?";
}
// Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
return '确定要关闭窗口吗>现代浏览器?';
}