Skip to content

Instantly share code, notes, and snippets.

@brandonb927
Created May 26, 2012 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonb927/2794652 to your computer and use it in GitHub Desktop.
Save brandonb927/2794652 to your computer and use it in GitHub Desktop.
JS: Get favicons beside links
/* JS */
function getDomain(url) {
return url.match(/:\/\/(.[^/]+)/)[1];
}
$("a[href^='http']").each(function() {
$(this).css({
background: "url(http://www.google.com/s2/u/0/favicons?domain=" + getDomain(this.href) +
") left center no-repeat",
"padding-left": "20px"
});
});
/* LESS/CSS */
a {
display: block;
text-decoration: none;
padding: 5px;
}
/* HTML */
<a href=http://github.com>GitHub</a>
<a href=http://css-tricks.com>CSS-Tricks</a>
<a href=http://www.google.com>Google</a>
<a href=http://www.brandonb.ca>Brandonb.ca</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment