【发布时间】:2016-11-02 09:00:20
【问题描述】:
我有以下 javascript 让网页标题每五秒一次又一次地改变。
<script>
var titleArray = ["TITLE-1","TITLE-2","TITLE-3","TITLE-4"];
var N = titleArray.length;
var i = 0;
setInterval(func,5000);
function func(){
if (i == 4) {
i = 0;
}
document.title = titleArray[i];
i++;
}
</script>
我希望它仅在用户打开不同的选项卡以“吸引”他/她回到我的网站时才起作用。当他/她在我的网站上时,我希望此 javascript 停止工作,因此标题为网页就是我简单写在标题标签中的内容。
这里是我想要的摘要。
<script>
if (the user is not on this tab but has opened and is using a different tab)
{the javascript I have mentioned above};
elce {nothing so the title tags work};
</script>
P.S:这是个好主意吗?还有其他建议吗?我真的很喜欢跳出框框思考。
【问题讨论】:
-
顺便说一句——那真是令人讨厌的行为
标签: javascript jquery title titlebar