Show Favicon for external Link with jQuery


/ Published in: jQuery
Save to your folder(s)

Source: http://css-tricks.com/favicons-next-to-external-links/


Copy this code and paste it in your HTML
  1. function getDomain(url) {
  2. return url.match(/:\/\/(.[^/]+)/)[1];
  3. }
  4.  
  5. $("a[href^='http']").each(function() {
  6. $(this).css({
  7. background: "url(http://favicon.yandex.net/favicon/" + getDomain(this.href) +
  8. ") left center no-repeat",
  9. "padding-left": "20px"
  10. });
  11. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.