在看到别人博客的时候发现在页面切换时,博客的标题也会更换,感觉蛮有意思的,而且感觉很容易,就想自己做一个js文件试试。
首先新建一个js文件。

window.onblur = function () {
    document.title = "回来qwq";
};
window.onfocus = function () {
    document.title = "嘿嘿(●ˇ∀ˇ●)";
}

这样就可以在页面失去焦点和点击页面的时候更换标题,但其他博客都是在页面重新获得焦点后几秒后恢复原标题,所以我又加了一些内容

var a = document.title;
function hello() {

    document.title = a;
}
window.onload = function () {
    var a = document.title;
};
window.onblur = function () {
    document.title = "回来qwq";
};
window.onfocus = function () {
    document.title = "嘿嘿(●ˇ∀ˇ●)";
    setTimeout(hello, 1000);
}

这样就是我的理想效果了。
我将js文件放在了github库,可以通过https://gcore.jsdelivr.net/gh/capabler1/cdn@master/js/hititle.js 访问。也可以自己diy。


一个好奇的人