Skip to content Skip to sidebar Skip to footer

Adding Favicons With Generic Option

I'd like to add favicons to my site using favicon.ico. however I want to load a generic icon if the site does not provide one. How can I test for the presense of a favicon and if o

Solution 1:

You could use some JavaScript. Adapt to suit...

var img = document.getElementsByTagName('img')[0],
    favicon = new Image;

favicon.onerror = function() {
    img.src = 'http://some-other-url.com/favicon.ico';
}

favicon.src = 'http://example.com/favicon.ico';

Post a Comment for "Adding Favicons With Generic Option"