Monday, September 27, 2010

Chat Application

So I'm writing this chat application and I need the browser to blink on the start bar when it's minimized. Near as I can tell this is impossible, however, I can make the title change in a blinking-like fashion to hopefully catch the eye. Perhaps if I added playing a sound to this it might be even better... anyhow, here's probably the best way to do it:

function blinkTitle ( text ) {
var oldTitle = document.title;
var msg = text || "New!";
var timeoutId = setInterval(function() {
document.title = document.title == msg ? ' ' : msg;
}, 1000);
window.onFocus = function() {
clearInterval(timeoutId);
document.title = oldTitle;
window.onfocus = null;
};
}