javascript实现“系统可能不会保存您所做的更改 实现 是否离开”

页面事件的执行:

页面加载时只执行onload 

页面关闭时先执行onbeforeunload,最后onunload 

页面刷新时先执行onbeforeunload,然后onunload,最后onload  

<!DOCTYPE html>
 <head>
  <meta charset="UTF-8">
  <title>测试</title>
  <script>
    function checkLeave(){
      event.returnValue="确定离开当前页面吗?";
    }
   </script>
 </head>
 <body onbeforeunload="checkLeave()">
  测试
 </body>
</html>

参考:https://www.jb51.net/article/130010.htm

原文地址:https://www.cnblogs.com/AlexanderZhao/p/12878900.html