var e = window.event || e
console.log(e)
}
window.onunload = function (e) {
var e = window.event || e
console.log(e)
}
window.onbeforeunload = function (e) {
var e = window.event || e
console.log(e)
}
注:
页面加载时只执行onload
页面关闭时先执行onbeforeunload,最后onunload
页面刷新时先执行onbeforeunload,然后onunload,最后onload
监听浏览器离开页面的操作:οnbefοreunlοad具体如下:
<body οnbefοreunlοad="goodbye()">
window.οnbefοreunlοad=function(e){
var e = window.event||e
e.returnValue=("确定离开当前页面吗?")
}
不知道你说的不行是什么原因,可以贴出代码看看