window.onbeforeunload = onbeforeunload_handler; function onbeforeunload_handler(){ if(event.clientX<=0 || event.clientY<0) { // alert("关闭"); return ''; }else{// alert("刷新或离开"); } }