Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker DevOps


JavaScript 监听标签页切换

JavaScript 大约 1017 字

onvisibilitychange

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        document.onvisibilitychange = function () {
            if (document.visibilityState == "hidden") {
                document.title = "waiting for you!";
            } else {
                document.title = "welcome back~";
            }
        }
    </script>
</head>

<body>
    Hello document visibilitychange
</body>

</html>

onfocus onblur

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onfocus = function () {
            document.title = "welcome back~";
        };
        window.onblur = function () {
            document.title = "waiting for you!";
        };
    </script>
</head>

<body>
    Hello window focus blur
</body>

</html>

说明

onfocusonblur能监听不同窗口之间的切换,更符合使用场景。

阅读 885 · 发布于 2021-06-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批