我试图得到的标题栏闪光,使用非常基本的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);
}
}发布于 2011-03-10 01:32:28
此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);
});发布于 2015-04-30 21:23:27
当访问者未查看当前浏览器页面(窗口隐藏、模糊)时,您会询问document.title栏是否闪烁(闪烁)。所以我们必须设置两个函数。首先,我们需要检测浏览器窗口当前是否处于活动状态- visibilityChange(actionFunction)。其次,我们需要开始获取闪烁的条形图- comeBackAlerts()。给你--这个解决方案对我来说很好,希望对你也一样。
/* Set event leaving the page to execute actionFunction */
function visibilityChange(actionFunction) {
window.focus(); /* window.onfocus = infoIn; */
var hidden = "hidden";
/* Standards: */
if (hidden in document) {
document.addEventListener("visibilitychange", actionFunction);
} else if ((hidden = "mozHidden") in document) {
document.addEventListener("mozvisibilitychange", actionFunction);
} else if ((hidden = "webkitHidden") in document) {
document.addEventListener("webkitvisibilitychange", actionFunction);
} else if ((hidden = "msHidden") in document) {
document.addEventListener("msvisibilitychange", actionFunction);
}
/* IE 9 and lower: */
else if ("onfocusin" in document) {
document.onfocusin = document.onfocusout = actionFunction;
}
/* All others: */
else {
window.onpageshow = window.onpagehide = window.onfocus = window.onblur = actionFunction;
}
}
/* Function to make browser window blink in task bar */
var comeBackAlerts = (function() {
var oldTitle = document.getElementsByTagName('h1')[0].innerText; /* document.title; */
var msg = "Arbir.ru";
var intervalId;
var blink = function() {
intervalId = setInterval(function() {
/* document.title = document.title == msg ? ' ' : msg; */
if (document.title == msg) {
document.title = oldTitle;
} else {
document.title = msg;
}
}, 1000);
};
var clear = function() {
clearInterval(intervalId);
document.title = oldTitle;
window.onmousemove = null;
window.onmouseout = null;
intervalId = null;
};
return function() {
if (!intervalId) {
blink();
window.onmousemove = clear;
}
};
}());
/* Running the functions */
visibilityChange(comeBackAlerts);https://stackoverflow.com/questions/5249692
复制相似问题