没有合适的资源?快使用搜索试试~ 我知道了~
首页JS针对浏览器窗口关闭事件的监听方法集锦
JS针对浏览器窗口关闭事件的监听方法集锦
3.1k 浏览量
更新于2023-05-26
评论
收藏 52KB PDF 举报
本文实例总结了JS针对浏览器窗口关闭事件的监听方法。分享给大家供大家参考,具体如下: 方式一:(适用于IE浏览器,而且刷新不提示,只在点击浏览器关闭按钮的时候提示) [removed] [removed]=onclose; function onclose() { if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey) { return "您要离开吗?"; } } [removed] 方式二:适用于IE和FF,不区分刷新和关闭
资源详情
资源评论
资源推荐

JS针对浏览器窗口关闭事件的监听方法集锦针对浏览器窗口关闭事件的监听方法集锦
本文实例总结了JS针对浏览器窗口关闭事件的监听方法。分享给大家供大家参考,具体如下:
方式一:(适用于IE浏览器,而且刷新不提示,只在点击浏览器关闭按钮的时候提示)
<script type="text/javascript">
window.onbeforeunload=onclose;
function onclose()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
return "您要离开吗?";
}
}
</script>
方式二:适用于IE和FF,不区分刷新和关闭
<script type="text/javascript">
window.onbeforeunload = onbeforeunload_handler;
window.onunload = onunload_handler;
function onbeforeunload_handler(){
var warning="确认退出?";
return warning;
}
function onunload_handler(){
var warning="谢谢光临";
alert(warning);
}
</script>
方式三:适用于IE和FF,不区分刷新和关闭,最简单的
<script type="text/javascript">
window.onbeforeunload=onclose;
function onclose()
{
return "您确定退出吗?";
}
</script>
方式四:适用于IE和FF,不区分刷新和关闭,稍复杂的
<script language="javascript">
var MSG_UNLOAD="如果你此时离开档案系统,所做操作信息将全部丢失,是否离开?";
var UnloadConfirm = {};
//启用监听浏览器刷新、关闭的方法
UnloadConfirm.set = function(confirm_msg){
window.onbeforeunload = function(event){
event = event || window.event;
event.returnValue = confirm_msg;
}
}
//关闭监听浏览器刷新、关闭的方法
UnloadConfirm.clear = function(){
window.onbeforeunload = function(){};
}
UnloadConfirm.set(MSG_UNLOAD);
</script>
方式五:只适用于IE6下的关闭按钮和快捷键关闭的,刷新不提示
<script type="text/javascript">
window.onbeforeunload=onclose;
function onclose()
{
var warnning = '<fmt:message key="systemMessage.exitWarning" />';
var beforeExit='<fmt:message key="systemMessage.beforeExitWarning" />';
if(event.clientY<0 && event.clientX>document.body.clientWidth-20 || event.clientY<0 && event.clientX<20 ||
event.altKey || event.ctrlKey || event.clientY>document.body.clientHeight){
alert(beforeExit);
return warnning;
}














安全验证
文档复制为VIP权益,开通VIP直接复制

评论0