如何做到用户离开博客然后改变网页的标题,卖个萌之类的,效果如下:
2
我们只需将以下代码输进博客模板的:自定义head 头部的HTML代码
代码如下,如果对你有帮助记得评个论~

       <script type="text/javascript">
      /*  动态网页标题*/
     var OriginTitile = document.title,
      titleTime;
     document.addEventListener("visibilitychange",
     function() {
      if (document.hidden) {
        $('[rel="shortcut icon"]').attr("href", "https://tianlong-1256081046.cos.ap- 
    chengdu.myqcloud.com/%E5%9B%BE%E7%89%87/favicon.ico");
        document.title = "你别走吖 Σ(っ °Д °;)っ";
        clearTimeout(titleTime)
    } else {
        $('[rel="shortcut icon"]').attr("href", "https://tianlong-1256081046.cos.ap- 
    chengdu.myqcloud.com/%E5%9B%BE%E7%89%87/favicon.ico");
        document.title = "你可算回来了 (。•ˇ‸ˇ•。)" + OriginTitile;
        titleTime = setTimeout(function() {
            document.title = OriginTitile
        },
        2000)
    }
    });
    </script>