前言
咱们常常逛他人的网站,有些网站当咱们脱离该页面浏览其他页面的时候,咱们在脱离的页面上面会看到比如本站的“你别走吖 Σ(っ °Д °;)っ”这样的字样,当咱们点回来的时候页面上面会看到“(/≧▽≦/)你又回来了!”的字样。那么咱们怎么完成呢?其实很简单,只需一句javascript句子即可完成。请看下面的教程。
预览图
教程
放在后台主题设置—>自定义代码—>自定义javascript代码把下面的代码添加到里面即可实现。
js代码
//<a target="_blank" href="https://www.yjjmt.com/tag/%e5%8a%a8%e6%80%81%e6%a0%87%e9%a2%98" title="View all posts in 动态标题">动态标题</a>var OriginTitile = document.title,titleTime;document.addEventListener("visibilitychange",function() {if (document.hidden) {document.title = "你别走吖 Σ(っ °Д °;)っ";clearTimeout(titleTime)} else {document.title = "(/≧▽≦/)你又回来啦! " ;titleTime = setTimeout(function() {document.title = OriginTitile},2000)}});//<a target="_blank" href="https://www.yjjmt.com/tag/%e5%8a%a8%e6%80%81%e6%a0%87%e9%a2%98" title="View all posts in 动态标题">动态标题</a> var OriginTitile = document.title, titleTime; document.addEventListener("visibilitychange", function() { if (document.hidden) { document.title = "你别走吖 Σ(っ °Д °;)っ"; clearTimeout(titleTime) } else { document.title = "(/≧▽≦/)你又回来啦! " ; titleTime = setTimeout(function() { document.title = OriginTitile }, 2000) } });//动态标题 var OriginTitile = document.title, titleTime; document.addEventListener("visibilitychange", function() { if (document.hidden) { document.title = "你别走吖 Σ(っ °Д °;)っ"; clearTimeout(titleTime) } else { document.title = "(/≧▽≦/)你又回来啦! " ; titleTime = setTimeout(function() { document.title = OriginTitile }, 2000) } });
注:代码中“你别走吖 Σ(っ °Д °;)っ”和“(/≧▽≦/)你又回来啦!”可自行修改成自己喜欢的标题文字。
- 如果你的网站主题设置没有自定义javascript代码这个框的话,若有自定义头部HTML代码的话,把下面的代码添加到里面也可实现。
- 或者在首页文件位于“</hesd>”标签之前添加下面的代码也可以。
<script type="text/javascript">/* 动态标题*/var OriginTitile = document.title,titleTime;document.addEventListener("visibilitychange",function() {if (document.hidden) {document.title = "你别走吖 Σ(っ °Д °;)っ";clearTimeout(titleTime)} else {document.title = "(/≧▽≦/)你又回来啦!" ;titleTime = setTimeout(function() {document.title = OriginTitile},2000)}});</script><script type="text/javascript"> /* 动态标题*/ var OriginTitile = document.title, titleTime; document.addEventListener("visibilitychange", function() { if (document.hidden) { document.title = "你别走吖 Σ(っ °Д °;)っ"; clearTimeout(titleTime) } else { document.title = "(/≧▽≦/)你又回来啦!" ; titleTime = setTimeout(function() { document.title = OriginTitile }, 2000) } }); </script><script type="text/javascript"> /* 动态标题*/ var OriginTitile = document.title, titleTime; document.addEventListener("visibilitychange", function() { if (document.hidden) { document.title = "你别走吖 Σ(っ °Д °;)っ"; clearTimeout(titleTime) } else { document.title = "(/≧▽≦/)你又回来啦!" ; titleTime = setTimeout(function() { document.title = OriginTitile }, 2000) } }); </script>

© 版权声明
THE END
暂无评论内容