JS 在窗口切换时改变页面标题
2021-05-04 19:07:00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 获取原始的页面标题
var normal_title = document.title;
// 监听页面的可见性
document.addEventListener('visibilitychange', function () {
if (document.visibilityState == 'hidden') {
// 如果页面不可见
// 设定新标题
document.title = 'Oops! 页面崩溃了!';
} else {
// 欢迎信息
document.title = "[✌] "+normal_title;
// 1 秒后恢复原始信息
setTimeout(function(){
document.title = normal_title
},1000)
}
});