当前位置: 代码迷 >> JavaScript >> JS监听浏览器封闭当前窗口
  详细解决方案

JS监听浏览器封闭当前窗口

热度:71   发布时间:2013-08-14 14:27:55.0
JS监听浏览器关闭当前窗口
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
</head>

<body>
  <script type="text/javascript">
  window.onbeforeunload = onbeforeunload_handler;  
    window.onunload = onunload_handler;  
    function onbeforeunload_handler(){  
        var warning="确认关闭当前窗口吗?";      
        //你的业务操作。。。。     
        return warning;  
    }  
      
    function onunload_handler(){  
        var warning="谢谢光临";
        //你的业务操作。。。。 
        alert(warning);  
    }  
  </script>
</body>
</html>
  相关解决方案