当用户在不同的选项卡中时,jQuery会更改页面的标题 [英] jQuery change page's title when user in a different tab
本文介绍了当用户在不同的选项卡中时,jQuery会更改页面的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想这应该是由jQuery完成的。你是否知道任何插件,我该怎么做?
解决方案
标题只能这样编辑:
document.title =blah;
所以你可以这样做:
var origTitle = document.title;
document.title =你有(+ x +)新消息 - + origTitle;
要使其闪烁,您必须使用 setTimeout()
;
var origTitle = document.title;
var isChatTab = false; //通过单独的DOM事件设置为true / false。
var animStep = true;
var animateTitle = function(){
if(isChatTab){
if(animStep){
document.title =你有(+ x +)新消息 - + origTitle;
} else {
document.title = origTitle;
}
animStep =!animStep;
} else {
document.title = origTitle;
animStep = false;
}
setTimeout(animateTitle,5000);
};
animateTitle();
I have live chat on my page. I want to change the title (with something moving like in omegle.com) when a new message is received and the user is not in the same tab as the live chat. When the user returns to the tab, the title would return to normal.
I guess it should be done by jQuery. Do you know any plugins or how can I do that?
解决方案
Title can only be edited like so:
document.title = "blah";
So you could do:
var origTitle = document.title;
document.title = "You have ("+x+") new messages - "+origTitle;
To make it flash you would have to do something with setTimeout()
;
var origTitle = document.title;
var isChatTab = false; // Set to true/false by separate DOM event.
var animStep = true;
var animateTitle = function() {
if (isChatTab) {
if (animStep) {
document.title = "You have ("+x+") new messages - "+origTitle;
} else {
document.title = origTitle;
}
animStep = !animStep;
} else {
document.title = origTitle;
animStep = false;
}
setTimeout(animateTitle, 5000);
};
animateTitle();
这篇关于当用户在不同的选项卡中时,jQuery会更改页面的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文