goo*_*ing 4 html javascript dom
我在我的页面上有实时聊天.当收到新邮件且用户与实时聊天不在同一选项卡中时,我想更改标题(在omegle.com中移动的内容).当用户返回选项卡时,标题将恢复正常.
我想它应该由jQuery完成.你知道任何插件或我该怎么做?
Jos*_*son 13
标题只能这样编辑:
document.title = "blah";
Run Code Online (Sandbox Code Playgroud)
所以你可以这样做:
var origTitle = document.title;
document.title = "You have ("+x+") new messages - "+origTitle;
Run Code Online (Sandbox Code Playgroud)
为了让它闪现,你必须做点什么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();
Run Code Online (Sandbox Code Playgroud)