PDA

View Full Version : Website favicon



Sokco
19 Mar 2011, 03:03 PM
Hey, im trying to get the favicon of most sites, im working with the following code:

<a href='javascript:(function(){links = document.getElementsByTagName("link"); wHref=window.location.protocol + "//" + window.location.hostname + "/favicon.ico"; for(i=0; i
<links.length; i++){s=links[i].rel; if(s.indexOf("icon") != -1){ wHref = links[i].href }; }; w = window.open(wHref, "Shortcut icon", "width=200, height=200"); })();'>Get Favicon</a>
this code only gets the favicon of the site you are on, how can i make it so that it could be for any site.

adiian
19 Mar 2011, 03:31 PM
Read and parse the html code, practically rewrite the above javascript code in the the language of your choice. Javascript is not appropriate because it runs on the browser side. You can choose php/ java / c#/ python/ ...

You should also check the root of the domain if no reference is found in html. Something like this: "http://domain.com/favicon.ico";