Thursday, March 26, 2009

jQuery.favicon - jQuery plugin for adding favicons next to the links

It's easy to add little favicons next to all or external links using CSS's background properties:

a[href ^=""] {
background: url( center right no-repeat;
padding-right: 16px;

But, to automate that for all links in a page, I wrote a nifty jQuery plugin--favicon (posted to jQuery group).

Side note

I don't know of anyway to parse the domain name of a link using JavaScript and so thought of using RFC compliant regexp and had to write a PHP helper to import regexp in JavaScript:

// Generate JavaScript regexp for matching URL for getting host part
// set user agent; otherwise getting 403
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT5.1; en-US; rv: Gecko/20071127 Firefox/');
echo str_replace(array(
"\n", // remove newline
'/', // escape / to \/
'?:' // remove--we really need mach
) , array(
) , file_get_contents(''));

1 comment:

john said...
This comment has been removed by a blog administrator.