使用js实现离开和进入页面时改变title和ico图标

介绍

实现离开当前标签页面,会改变ico图标和标题!

代码

<script>
var OriginTitile = document.title,
titleTime;
document.addEventListener("visibilitychange",
function() {
    if (document.hidden) {
        $('[rel="shortcut icon"]').attr("href", "//https://photo.joey.cf/images/2018/03/10/52T2.png");
        document.title = "页面已崩溃!点击恢复!";
        clearTimeout(titleTime)
    } else {
        $('[rel="shortcut icon"]').attr("href", "//https://photo.joey.cf/images/2018/03/10/52T2.png");
        document.title = "(/≧▽≦/)咦!又好了! " + OriginTitile;
        titleTime = setTimeout(function() {
            document.title = OriginTitile
        },
        2000)
    }
});
</script>

使用方法

  • 把这段js加到header.php(typecho博客)</body>的前面即可。
  • 把其中的两个ico图标换成你自己的即可!

扫描二维码,在手机上阅读!
Last modification:November 20th, 2018 at 11:29 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment