window.onbeforeunload

          //可阻止页面刷新、跳转、关闭
          window.onbeforeunload = function(event){
            event=event||window.event;
            event.returnValue="确定要离开当前页面?";
          };
          //而window.onunload不会阻止页面刷新、跳转或关闭,只是在走前留下一句话

  

原文地址:https://www.cnblogs.com/frostbelt/p/2643815.html