Web development , php , ajax , symfony, framework, zend
In: web resources
22 May 2009I recently came upon an interesting jQuery article about how you can retrieve all external links within a page, build the address of the site’s favorite icon, and place the favorite icon along side the link. I’ve chosen a different approach which uses CSS to position the favorite icon as a background image.
.favicon { background-repeat:no-repeat; padding:2px 0 3px 22px; }
This CSS code will provide padding and background image placement for the link.
/* when the dom is ready... */
window.addEvent('domready',function() {
/* grab all complete linked anchors */
$$('a[href^="http://"]').each(function(a) {
/* if it's not on the davidwalsh.name domain */
if(!a.get('href').contains(window.location.host)) {
/* get the favicon */
var favicon = a.get('href').replace(/^(http:\/\/[^\/]+).*$/, '$1') + '/favicon.ico';
/* place it in the anchor */
a.setStyle('background-image','url(' + favicon + ')').addClass('favicon');
}
});
});
I’ve chosen to include the favorite icon as a background image as opposed to the jQuery article’s method of injecting an image.
Would you use this method on your website?
Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!
This blog delivers stylish and dynamic news for designers and web-developers on all subjects of design, ranging from: CSS, Ajax, Javascript, web design, graphics, typography, advertising & much more. Our goal is to help you communicate effectively on the web with an engaging website or functional interface.



