一个浏览器中有多个页面,我希望的是只有在关闭浏览器时才执行某段代码。
网上查到了下面这个方法,但是为什么关闭浏览器时候chrome什么都没有alert呢?
应该怎么做才可以做到这样的效果呢?
window.onbeforeunload=function ()
{
alert("===onbeforeunload===");
if(event.clientX>document.body.clientWidth && event.clientY < 0 || event.altKey)
{
alert("你关闭了浏览器");
}
else
{
alert("你正在刷新页面");
}
}