favicon.js 623 B

1234567891011121314151617181920
  1. /*!
  2. * Dynamically changing favicons with JavaScript
  3. * Works in all A-grade browsers except Safari and Internet Explorer
  4. * Demo: http://mathiasbynens.be/demo/dynamic-favicons
  5. */
  6. // HTML5™, baby! http://mathiasbynens.be/notes/document-head
  7. document.head = document.head || document.getElementsByTagName('head')[0];
  8. function changeFavicon(src) {
  9. var link = document.createElement('link'),
  10. oldLink = document.getElementById('dynamic-favicon');
  11. link.id = 'dynamic-favicon';
  12. link.rel = 'shortcut icon';
  13. link.href = src;
  14. if (oldLink) {
  15. document.head.removeChild(oldLink);
  16. }
  17. document.head.appendChild(link);
  18. }