1. 新建文件\source\js\title.js,写入以下内容(注意更改成自己的文本):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//动态标题
var OriginTitile = document.title;
var titleTime;
document.addEventListener("visibilitychange", function () {
if (document.hidden) {
//离开当前页面时标签显示内容
document.title = "切换至其他网站时的标题";
clearTimeout(titleTime);
} else {
//返回当前页面时标签显示内容
document.title = "返回博客时的标题";
//两秒后变回正常标题
titleTime = setTimeout(function () {
document.title = OriginTitile;
}, 2000);
}
});
  1. 在主题配置文件_config.butterfly.yml引入该文件:
1
2
3
inject:
bottom:
+ - <script async src="/js/title.js"></script>
  1. hexo 三连