Using JavaScript/jQuery to update the browser window title bar

So, I have this little chat app that’s using the wonderful Pusher to support Websockets with a fall-back to Flash. If you’re interested in Websockets, I definitely recommend taking a look at Pusher.

Using Pusher to show new messages etc was the easy part. The tricky thing (for me, at least) was figuring out how to update the browser tab’s title. I wanted to show an unread messages count if the chat window was inactive. For example:


When the chat window is made active again, the unread messages count should be gone.

Sounds easy, right? Well, it was, for the most part. The only catch was that I had to use setTimeout() to get things working reliably across browsers. I’m not sure why.

Anyway, here’s the relevant code:


Published by

Trevor Turk

A chess-playing machine of the late 18th century, promoted as an automaton but later proved a hoax.