关闭浏览器当前页面的方法和阻止浏览器关闭的方法
发布于 2017-11-05 18:05:53
2827 次浏览
function CloseWebPage(){
if (navigator.userAgent.indexOf("MSIE") > 0) {
if (navigator.userAgent.indexOf("MSIE 6.0") > 0) { //适用于ie6不带提示关闭窗口
window.opener = null;
window.close();
} else {
window.open('', '_top'); //ie7之后不提示关闭窗口
window.top.close();
}
}
else if (navigator.userAgent.indexOf("Firefox") > 0) { //Firefox不提示关闭窗口
window.location.href = 'about:blank ';
} else {
window.opener = null;
window.open('', '_self', ''); //其他浏览器
window.close();
}
}
阻止关闭的方法:
$(window).bind('beforeunload',function(){
return '您输入的内容尚未保存,确定离开此页面吗?';
});