Return to Snippet

Revision: 17119
at August 24, 2009 08:46 by batamire


Initial Code
jQuery('a[href^="http://"]').filter(function(){
     return this.hostname && this.hostname !== location.hostname;
}).each(function() {
    var link = jQuery(this);
    var faviconURL =
      link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/favicon.ico';
    var faviconIMG = jQuery('<img src="favicon.png" alt="" />')['appendTo'](link);
    var extImg = new Image();
    extImg.src = faviconURL;
    if (extImg.complete)
      faviconIMG.attr('src', faviconURL);
    else
      extImg.onload = function() { faviconIMG.attr('src', faviconURL); };
});

Initial URL
http://blog.liviuholhos.com/javascript/add-a-favicon-near-external-links-with-jquery

Initial Description
From Liviu HolhoÅŸ - Blog

http://blog.liviuholhos.com/javascript/add-a-favicon-near-external-links-with-jquery

Initial Title
Add a favicon near external links with jQuery

Initial Tags
link, jquery

Initial Language
jQuery