天天看点

判断浏览器是刷新还是关闭的js代码

<script type="text/javascript">

    window.onbeforeunload = function () {

        var n = window.event.screenX - window.screenLeft;

        var b = n > document.documentElement.scrollWidth - 20;

        if (b && window.event.clientY < 0 || window.event.altKey) {

            alert("是关闭而非刷新");          

            window.event.returnValue = "人";  // 这里可以放置你想做的操作代码     

        } else {

            alert("是刷新而非关闭");

        }

    }

</script>

转载于:https://www.cnblogs.com/wgx0428/archive/2012/03/09/2387855.html

继续阅读