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
- First create a javascript function, i named it as onerror_show_default.
-
-
<script type="text/javascript">
-
function onerror_show_default()
-
{
-
var img = document.getElementsByTagName(‘img’)[0],
-
img.src = ‘http://localhost/image/favicon.ico’;
-
}
-
</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]“/>
-
-
<img
-
src="http://www.facebook.com/favicon.ico"
-
onerror="onerror_show_default"/>
-

Posted in 


