怎么判断标签页和关闭浏览器关闭? 我希望页面关闭时触发一段javascript代码,但是关闭标签页和关闭浏览器不触发onunload()事件,不知道该怎么办。或者请高手告诉我如何判断标签页或者浏览器关闭。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 window.onbeforeunload = function() { var n = window.event.screenX - window.screenLeft; var b = n > document.documentElement.scrollWidth - 20; if (b && window.event.clientY < 0 || window.event.altKey) { alert("是关闭而非刷新"); } else { alert("是刷新而非关闭"); } } //考虑到兼容<script> function window.onbeforeunload() { if(event.clientX>360&&event.clientY<0) { window.event.returnValue="提示:\“退出系统\”请点系统的\“安全退出\”!"; } } $(document).bind("onbeforeunload",function(){return false;}) </script></head><body onbeforeunload='return "提示:\“退出系统\”请点系统的\“安全退出\”!"'></body></html> //考虑到兼容<script> function window.onbeforeunload() { if(event.clientX>360&&event.clientY<0) { window.event.returnValue="提示:\“退出系统\”请点系统的\“安全退出\”!"; } } //$(document).bind("onbeforeunload",function(){return false;}) </script></head><body onbeforeunload='return "提示:\“退出系统\”请点系统的\“安全退出\”!"'></body></html> onbeforeunload()我试过也不行啊。我的是IE9浏览器。 问个正则表达式的验证 一个简单日历控件不知怎么调用 怎么用JavaScript编写计算器? onmouseover问题 JS赋值无效,在线等,急!!! 关于javascript table td 中 有 多个 innerhtml的问题。 时间格式问题 如何动态取值? 求浮动广告的代码 仅留浏览器的标题条,能把菜单条、工具条、状态条、地址条设为不显示吗?50分,马上给~ 帮忙调整下效果 正则表达式的问题
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth - 20;
if (b && window.event.clientY < 0 || window.event.altKey) {
alert("是关闭而非刷新");
} else {
alert("是刷新而非关闭");
}
}
//考虑到兼容
<script>
function window.onbeforeunload()
{
if(event.clientX>360&&event.clientY<0)
{
window.event.returnValue="提示:\“退出系统\”请点系统的\“安全退出\”!";
}
}
$(document).bind("onbeforeunload",function(){return false;})
</script>
</head><body onbeforeunload='return "提示:\“退出系统\”请点系统的\“安全退出\”!"'></body>
</html>
<script>
function window.onbeforeunload()
{
if(event.clientX>360&&event.clientY<0)
{
window.event.returnValue="提示:\“退出系统\”请点系统的\“安全退出\”!";
}
}
//$(document).bind("onbeforeunload",function(){return false;})
</script>
</head><body onbeforeunload='return "提示:\“退出系统\”请点系统的\“安全退出\”!"'></body>
</html>