关闭页面前提示或保存数据

<script type="text/javascript">
  window.onbeforeunload = function(event) {//event写不写都无所谓    这里也可用其他方法操作    执行前提是页面有过修改

          document.getElementById('dd').innerHTML="W3Cschool";//关闭页面这句会执行  firefox 以及 Microsoft Edge可以
      return "数据保存中...";//return必须要
  }

.......

<body>
    <p id="dd"></p>

......

原文地址:https://www.cnblogs.com/LiuPan2016/p/6101820.html