Skip to content

Instantly share code, notes, and snippets.

@larchanka
Forked from mathiasbynens/change-favicon.js
Created September 28, 2015 11:34
Show Gist options
  • Save larchanka/b4fea48689b2ef68dc32 to your computer and use it in GitHub Desktop.
Save larchanka/b4fea48689b2ef68dc32 to your computer and use it in GitHub Desktop.
Dynamically changing favicons with JavaScript
/*!
* Dynamically changing favicons with JavaScript
* Works in all A-grade browsers except Safari and Internet Explorer
* Demo: http://mathiasbynens.be/demo/dynamic-favicons
*/
// HTML5™, baby! http://mathiasbynens.be/notes/document-head
document.head || (document.head = document.getElementsByTagName('head')[0]);
function changeFavicon(src) {
var link = document.createElement('link'),
oldLink = document.getElementById('dynamic-favicon');
link.id = 'dynamic-favicon';
link.rel = 'shortcut icon';
link.href = src;
if (oldLink) {
document.head.removeChild(oldLink);
}
document.head.appendChild(link);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment