[英]Flash the title bar
我嘗試使用非常基本的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);
}
}
這個重復使我的瀏覽器閃爍作為指示
但是因為我現在正在編寫這個腳本:
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);
});
當訪問者沒有查看當前瀏覽器頁面時(窗口隱藏,模糊),您詢問有關閃爍(閃爍)document.title欄的問題。 所以我們必須設置兩個功能。 首先,我們需要檢測瀏覽器窗口當前是否處於活動狀態 - visibilityChange(actionFunction)。 第二,我們需要開始獲取flashing文件。標題欄 - 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.