onbeforeunload

window.onbeforeunload  = function() {   
      var n = window.event.screenX - window.screenLeft;
      if ((n > document.documentElement.scrollWidth - 20) && (window.event.clientY < 0) || window.event.altKey) {   
          alert("是关闭而非刷新");   
          window.event.returnValue = "是否关闭?";
      } else {
           alert("是刷新而非关闭");   
      }   
}

你可能感兴趣的:(onbeforeunload)