以Hexo博客系统 Next主题为例

\themes\next\source\js\src目录下新建dytitle.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) {
$('[rel="icon"]').attr('href', "/img/TEP.ico");
document.title = ' 你不理我了!';
clearTimeout(titleTime);
}
else {
$('[rel="icon"]').attr('href', "/favicon.ico");
document.title = ' 么么哒 ' + OriginTitile;
titleTime = setTimeout(function () {
document.title = OriginTitile;
}, 2000);
}
});

更改\themes\next\layout\_layout.swig。在</body>之前添加:

1
2
<!--动态标题-->
<script type="text/javascript" src="/js/src/dytitle.js"></script>