欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

javascript判断页面是否是刷新还是关闭

程序员文章站 2022-04-04 17:13:50
...
  <script>
              function CloseOpen(event) {
                     if(event.clientX<=0 && event.clientY<0) {
                            alert("关闭");
                     }
                     else
                     {
                            alert("刷新或离开");
                     }
              }  
</script>


<body onunload="CloseOpen(event)">





<html>

<head>

<title>无忧脚本代码测试网页</title>

</head>

<body>

<script language=javascript>

windowonbeforeunload=function()

{

        if(eventclientX>documentbodyclientWidth)

        {

                alert('浏览器关闭');

        }

        else

{

                alert('浏览器刷新');

        }

}

</script>

</body>

</html>