Mar*_*ski 2 html javascript asp.net
我尝试使用非常基本的HTML将标题栏设置为flash.我已经给了它一个镜头,但下面的代码似乎不起作用,我不知道为什么.此外,有没有办法使标题栏闪存文本,但只有当用户没有查看当前的浏览器页面?
我的尝试:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这个重复使我的浏览器闪烁作为指示
但是因为我现在正在编写这个脚本:
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>
Run Code Online (Sandbox Code Playgroud)
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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10693 次 |
| 最近记录: |