在body中使用 onUnload="" 触发
如
<body onUnload="test();" ><script>
function test(){
alert("我被触发了! 是在关闭窗口的时候");
}
</script>
如
<body onUnload="test();" ><script>
function test(){
alert("我被触发了! 是在关闭窗口的时候");
}
</script>
function a()
{
if(event.clientY<0 && event.clientX>document.body.clientWidth){
alert("是窗口关闭");
}
else{
alert("是刷新");
}
}
</script>
<body onbeforeunload="a()">