Created
December 15, 2012 20:21
-
-
Save blat/4298873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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