我尝试使用非常基本的 HTML 使标题栏闪烁。我试了一下,但下面的代码似乎不起作用,我也不知道为什么。另外,有没有办法让标题栏闪烁文本,但前提是用户没有查看当前浏览器页面?
我的尝试:
function Flash() {
window.setTimeout(function() {
alert(document.title);
document.title = (document.title == "Company" ? "Company - flash text" : "Company");
}, 1000);
this.stop = function() {
document.title = "Company";
clearTimeout(this.timer);
}
}
最佳答案
这个的副本 make my browser blink as indicator
但是既然我现在写了这个脚本:
https://plungjan.name/SO/flashtitle.html
<script>
var timer="";
var isBlurred=false;
window.onblur=function() {
isBlurred = true;
timer=window.setInterval(function() {
document.title = document.title == "Company" ? "Company - flash text" : "Company";
}, 1000);
}
window.onfocus=function() {
isBlurred = false;
document.title = "Company";
clearInterval(timer);
}
</script>
jQuery 版本差别不大(但未测试)
var timer="";
var isBlurred=false;
$(window).on("blur",function() {
isBlurred = true;
timer=window.setInterval(function() {
document.title = document.title == "Company" ? "Company - flash text" : "Company";
}, 1000);
}).on("focus",function() {
isBlurred = false;
document.title = "Company";
clearInterval(timer);
});
关于javascript - 闪烁标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5249692/