How to capture browser close event in javascript
To detect if the user is closing the IE browser apart from onunload event, as it is triggerred when user does refresh etc
试了一晚上,还就jQuery版本的好使!其它写法都跟浏览器有关!
<html>
<head>
<script src="http://static.blog.csdn.net/scripts/jquery.js"
type="text/javascript"></script>
<title>Browser close button tracking</title>
<script>
$(window).bind("beforeunload", function() {
return "您输入的内容尚未保存,确定离开此页面吗";
});
</script>
</head>
<body>
Your page content
<p>event.clientY<0 && event.clientX>document.body.scrollWidth</p>
<p>jQuery(window).unbind("beforeunload"); alert("You are about to
close the browser window/tab");</p>
<p>//绑定beforeunload事件 $(window).bind(‘beforeunload’,function(){
return ‘您输入的内容尚未保存,确定离开此页面吗?’; });</p>
<p>//解除绑定 $(window).unbind(‘beforeunload’);</p>
</body>
</html>