Please enter your login details.
:FINALFURY:

all
wellbeing
projects
news
music
Displaying a favicon in HTML
(Monday 15th of October 2012 09:50:17 AM) (4609 views) (0 comments)
Reliably displaying favicons in HTML (and a little javascript) is really easy! Most websites simply store the their icon at the root of the website. So for example http://www.bbc.co.uk/favicon.ico looks like this "". However for IPlayer the BBC store the favicon in the page directory. So that's http://www.bbc.co.uk/iplayer/favicon.ico and looks like this "".

So for sites like IPlayer we need to fall-back to the site root icon but only after trying the page directory first. Unfortunately the HTML <img> tag doesn't have any way of doing this without a little help from javascript. Here's how..

<img src="http://www.bbc.co.uk/iplayer/favicon.ico" onerror='this.onerror = null; this.src="http://www.bbc.co.uk/favicon.ico"'> </img>

Easy, right?!

Please login to post comments.

Copyright © 2011 Christopher James Plant Page generated in 0.008 seconds using 5 database queries. Style & Emoticons: "Default" by Kaloth
Icons: "Small Icons" by WendellVerli