javascript 监听 窗口关闭和页面刷新事件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.onbeforeunload=onclose;
var aqqNumber = 23423423;
var intervalId ;
function onclose()
{
alert(aqqNumber);
window.event.returnValue = function(){clearInterval(intervalId);}; //这里可以放置你想做的操作代码
}
intervalId = setInterval('setNumber()',1000);
function setNumber(){
var num = Math.floor(Math.random()*10);
num = (num%3)+2;
aqqNumber += num;
console.log(num+"aqqNumber-"+aqqNumber);//ie不支持console对象,firefox,chrome都支持
}
//-->
</SCRIPT>
<script language=javascript>
/**
window.onbeforeunload=function (){
alert("===onbeforeunload===");
//if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey) {
if(event.clientX<=0 && event.clientY<0) {
alert("你关闭了浏览器");
window.event.returnValue = function(){clearInterval(intervalId);}; //这里可以放置你想做的操作代码
}else{
alert("你正在刷新页面");
}
}
*/
</script>
<script language=javascript>
</script>
</HEAD>
<body >
</BODY>
</HTML>