Skip to content

Instantly share code, notes, and snippets.

@blat
Created December 15, 2012 20:21
Show Gist options
  • Save blat/4298873 to your computer and use it in GitHub Desktop.
Save blat/4298873 to your computer and use it in GitHub Desktop.
var founded = false;
var checkFavicon = function(url) {
var image = new Image()
image.onload = function() {
if (!founded) {
founded = true;
alert(url);
}
};
image.src = url;
}
var searchFavicon = function() {
founded = false;
var links = document.getElementsByTagName('link');
for (i = 0; i < links.length; i++) {
var link = links[i];
var rel = link.getAttribute('rel');
if (rel.match(/icon/)) {
var favicon = link.getAttribute('href');
if (!favicon.match(/\/\//)) {
if (favicon.match(/^\//)) {
favicon = location.protocol + '//' +location.host + favicon;
} else {
favicon = location.protocol + '//' +location.host + '/' + favicon;
}
}
checkFavicon(favicon);
}
}
checkFavicon(location.protocol + '//' + location.host + '/favicon.ico');
}
searchFavicon();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment