I have a javascript chat. When a user receives a message, I want the title to blink until it becomes active. (like Gmail Talk)
For example:
My website
My website
and User says: bla bla
My website
How can I achieve that using jQuery ?
What i tried so far: (blinking never stop playing)
var isOldTitle = true;
var oldTitle = "oldTitle";
var newTitle = "newTitle";
function changeTitle() {
document.title = isOldTitle ? oldTitle : newTitle;
isOldTitle = !isOldTitle;
setTimeout(changeTitle, 700);
}
changeTitle();
Full solution:
var isOldTitle = true;
var oldTitle = "oldTitle";
var newTitle = "newTitle";
var interval = null;
function changeTitle() {
document.title = isOldTitle ? oldTitle : newTitle;
isOldTitle = !isOldTitle;
}
interval = setInterval(changeTitle, 700);
$(window).focus(function () {
clearInterval(interval);
$("title").text(oldTitle);
});