在网页中加入下列代码就知道效果了
<script>
function
window.onunload(){alert(这就是你要做的事,关闭网页之后做的!)}
function
window.onbeforeunload(){alert(这就是你要做的事,关闭网页之前做的!)}
</script>
<body
οnunlοad="yourfunction()">
如果响应onbeforeunload,或者onunload事件,那么就不只是ie关闭会触发事件,在页面刷新,或迁移等其他动作时,也可能会触发事件,所以我想应该这样
function
window.onbeforeunload()
{
if(event.clientx>360&&event.clienty<0||event.altkey)
{
//你的动作
}
}
如何判断关闭还是刷新
<script language=javascript>
function myunload()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
window.event.returnValue = "关闭窗口";
}
else{
window.event.returnValue = "刷新窗口";
}
}
</script>
如果用的是窗架集frameset,那么要在frameset里面写onbeforeunload事件,此时document.body.clientWidth要减去20