window.onbeforeunload = function(){ var n = window.event.screenX - window.screenLeft; var b = n > document.documentElement.scrollWidth-20; if(b && window.event.clientY < 0 ¦ ¦ window.event.altKey){ alert("关闭"); //关闭的代码 } else{ alert("刷新"); //刷新的代码 } }