jQuery判断当前页面是否被浏览

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>jQuery判断当前页面是否被浏览</title>
</head>

<body>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).on('visibilitychange', function(e) {
        if (e.target.visibilityState === "visible") {
            document.title = '被发现啦!';
        } else if (e.target.visibilityState === "hidden") {
            document.title = '藏好啦!';
        }
    });
    </script>
</body>

</html>

 

posted @ 2018-09-25 15:02  徐同保  阅读(403)  评论(0编辑  收藏  举报