基于JavaScript判断浏览器到底是关闭还是刷新

2025-04-19 02:33:45
推荐回答(1个)
回答1:

window.onbeforeunload=function (){
alert("===onbeforeunload===");
if(event.clientX>document.body.clientWidth && event.clientY < 0 || event.altKey){
alert("你关闭了浏览器");
}else{
alert("你正在刷新页面");
}
}