Favicon

The following example assume you’d like to display a list of URL and showing the favicon. If the favicon is not found the default will display instead.

Javascript

  1. First create a javascript function, i named it as onerror_show_default.
  1.  
  2. <script type="text/javascript">
  3. function onerror_show_default()
  4. {
  5.    var img = document.getElementsByTagName(‘img’)[0],
  6.    favicon = new Image();
  7.    img.src = ‘http://localhost/image/favicon.ico’;
  8. }
  9. </script>


How to get Favicon

There are few way to get favicon to display. But normally will place it right after the URL.
Example: http://www.facebook.com/favicon.ico

HTML

Next, in your img tag you have to add onerror=”[javascript_function_call]“/>

  1.  
  2. <img
  3.     src="http://www.facebook.com/favicon.ico"
  4.     onerror="onerror_show_default"/>
  5.  


Done!

You can leave a response, or trackback from your own site.

Leave a Reply

Security Code: