05 Jan 2008

Meebo And The Blinking Favicon

Meebo uses a cool blinking favicon as a notification for various events (messages, buddy login, signout). Here is a simple function to mimic the behaviour.

toggle = function () {
  favicon = document.getElementsByTagName ('link') [0];
  head = document.getElementsByTagName ('head') [0];
  url1 = 'http://google.com/favicon.ico';
  url2 = 'http://yahoo.com/favicon.ico';
  n = document.createElement ("link");
  n.setAttribute ('href', (favicon.href==url1) ? url2 : url1);
  n.setAttribute ('type', 'image/x-icon');
  n.setAttribute ('rel', 'shortcut icon');
  head.removeChild (favicon); head.appendChild (n);
  setTimeout (toggle, 500);

setTimeout (toggle, 500);

This assumes that the favicon link tag is the first link tag, you might make have to make changes if that is not the case.