Highlight external links with favicons

Many sites like to apply distinct styling to their external links to let users know they will leave the site if they click on them. Wikipedia is a good example of this, using a blue box-arrow icon applied as a background image to links with the "external" class.

A slight more colourful approach would be to use the target website's favicon. This not only makes for an arguably more visually appealing design, but in certain circumstances, allows users to quickly see to which domain a link will probably take them:

BeforeAfter
External links styled with an icon (left) and with the target site's favicon (right)

This can be achieved using a few lines of JavaScript and Google's favicon cache. Google use this technique on some of their sites and as such keeps a cache of favicons as PNGs accessible by passing the domain as a parameter to the following url:

http://s2.googleusercontent.com/s2/favicons?domain_url=[DOMAIN]

So for example:

<img src="http://s2.googleusercontent.com/s2/favicons?domain_url=http%3A//semplicewebsites.com" width="16" height="16" alt="Favicon" />

gives our favicon: Favicon. It also gives a nice fallback icon when a favicon isn't found: Favicon

The code

To being with we need our HTML...

<a href="http://www.google.com" class="external">Google</a>

... and some CSS rules...

a.external {
  padding-left: 18px;
  background: url('http://s2.googleusercontent.com/s2/favicons') left center no-repeat;
}

This also defines the fall-back icon for when JavaScript is disabled.

Then we add our JavaScript. For this I will assume that you are using a JavaScript framework that allows you to select an element with a CSS selector. In this example I am using jQuery:

$('a.external').each(function() {
  var host = $(this)[0].host.replace(':80', '');
  $(this)[0].style.backgroundImage =
    'url("http://s2.googleusercontent.com/s2/favicons?domain_url=' +
    escape('http://' + host) + '")';
});

This code is added to the bottom of the page, or a page load event. ":80" is added to the a.host value by IE6, so this is removed as it unnecessary for searching the Google cache.

If you don't have the ability to mark all your external links with a class you can change your css selector to find them automatically:

$('a[href^=http]').each(function() {
  ...
  ...
});

All scripts are Public Domain.

Comments

http://brooklynne.net/profiles/blogs/adagrin-sildenafil-citrate-200mg-co... http://newsmediaimages.ning.com/profiles/blogs/low-price-estradiol-2mg-b... http://neikasworld.ning.com/profiles/blogs/donde-a-la-orden-meloxicam-15... http://bygda.traktor.no/profiles/blogs/donde-para-ordenar-etodolaco-200m... http://bigtombolo.ning.com/profiles/blogs/d-nde-comprar-diclofenaco-sin-... http://www.q-voice.tv/old/redirect/test/qa/index.php?qa=71278&qa_1=compr... https://whanswerz.com/723/farmacia-online-donde-comprar-dapoxetina-barat... http://property.ning.com/profiles/blogs/levotiroxina-0-1mg-como-posso-co... http://newyorkundergroundradio.ning.com/profiles/blogs/acheter-vrai-en-l... http://weebattledotcom.ning.com/profiles/blogs/imdur-comprar-online-usa http://divasunlimited.ning.com/profiles/blogs/man-axcio-60mg-order-safel... http://kasabovart.ning.com/profiles/blogs/farmacia-online-donde-comprar-... http://techwarriorteam.ning.com/profiles/blogs/ofloxacine-comprar-en-far... http://www.facecool.com/profiles/blogs/farmacia-en-linea-donde-comprar-z... http://www.myslimfix.com/profiles/blogs/plavix-clopidogrel-75-mg-comprar... http://shamrockballerz.ning.com/profiles/blogs/como-fa-o-para-comprar-ge... http://answers.codelair.com/31695/cheap-clozapine-25mg-order-online-cloz... http://viatorfroshreligion.ning.com/profiles/blogs/buy-discount-buspiron... http://recampus.ning.com/profiles/blogs/altace-2-5mg-order-how-can-i-ord... http://ssbsavannah.ning.com/profiles/blogs/order-escitalopram-20mg-cheap...

get cialis 40 mg generic that Kids and Adults | [URL=https://generic-cialis-40-mg.com/#]cialis 40 mg[/URL] on feeding baby avocado

http://adrenalineprovinggrounds.ning.com/profiles/blogs/como-posso-compr... http://usguide101.com/qa/index.php?qa=1543789&qa_1=flutamide-ligne-achet... http://whazzup-u.com/profiles/blogs/piroxicam-20mg-onde-comprar-entrega-... http://stoopball.ning.com/profiles/blogs/achat-rapide-chlorambucil-2mg-c... http://newyorkundergroundradio.ning.com/profiles/blogs/achat-express-nap... http://thecorner.ning.com/profiles/blogs/farmacia-en-linea-donde-comprar... http://summerschooldns.ning.com/profiles/blogs/dynafil-sildenafil-citrat... http://www.onfeetnation.com/profiles/blogs/c-mo-realizar-un-pedido-panto... http://playit4ward-sanantonio.ning.com/profiles/blogs/c-mo-realizar-un-p... http://kutoos.unifiedly.com/blogs/post/217605 http://recampus.ning.com/profiles/blogs/proair-salmeterol-fluticasone-co... http://flutes.ning.com/profiles/blogs/fexofenadina-180mg-comprar-sin-rec... http://neolatino.ning.com/profiles/blogs/c-mo-realizar-un-pedido-trazodo... http://divasunlimited.ning.com/profiles/blogs/ciclofosfamida-50mg-onde-c... http://neikasworld.ning.com/profiles/blogs/order-ticason-0-5-0-05-mg-low... http://153.126.169.73/GaijinConcierge/index.php?qa=35744&qa_1=mellaril-t... http://tnfdjs.ning.com/profiles/blogs/pyridium-200mg-buy-no-prescription... http://brooklynne.net/profiles/blogs/bimatoprost-3-mg-puedo-comprar-r-pi... http://caisu1.ning.com/profiles/blogs/farmacia-online-donde-comprar-gene... http://crossroadshob.ning.com/profiles/blogs/c-mo-realizar-un-pedido-xel... http://stoopball.ning.com/profiles/blogs/hydrochlorothiazide-12-5mg-en-l... http://writeskills.ning.com/profiles/blogs/clomiphene-25-mg-en-ligne-bai... http://manchestercomixcollective.ning.com/profiles/blogs/achat-rapide-ci... http://property.ning.com/profiles/blogs/farmacia-online-donde-comprar-ge... http://newmediavault.ning.com/profiles/blogs/clomipramina-comprar-en-far...

http://adrenalineprovinggrounds.ning.com/profiles/blogs/como-posso-compr... http://usguide101.com/qa/index.php?qa=1543789&qa_1=flutamide-ligne-achet... http://whazzup-u.com/profiles/blogs/piroxicam-20mg-onde-comprar-entrega-... http://stoopball.ning.com/profiles/blogs/achat-rapide-chlorambucil-2mg-c... http://newyorkundergroundradio.ning.com/profiles/blogs/achat-express-nap... http://thecorner.ning.com/profiles/blogs/farmacia-en-linea-donde-comprar... http://summerschooldns.ning.com/profiles/blogs/dynafil-sildenafil-citrat... http://www.onfeetnation.com/profiles/blogs/c-mo-realizar-un-pedido-panto... http://playit4ward-sanantonio.ning.com/profiles/blogs/c-mo-realizar-un-p... http://kutoos.unifiedly.com/blogs/post/217605 http://recampus.ning.com/profiles/blogs/proair-salmeterol-fluticasone-co... http://flutes.ning.com/profiles/blogs/fexofenadina-180mg-comprar-sin-rec... http://neolatino.ning.com/profiles/blogs/c-mo-realizar-un-pedido-trazodo... http://divasunlimited.ning.com/profiles/blogs/ciclofosfamida-50mg-onde-c... http://neikasworld.ning.com/profiles/blogs/order-ticason-0-5-0-05-mg-low... http://153.126.169.73/GaijinConcierge/index.php?qa=35744&qa_1=mellaril-t... http://tnfdjs.ning.com/profiles/blogs/pyridium-200mg-buy-no-prescription... http://brooklynne.net/profiles/blogs/bimatoprost-3-mg-puedo-comprar-r-pi... http://caisu1.ning.com/profiles/blogs/farmacia-online-donde-comprar-gene... http://crossroadshob.ning.com/profiles/blogs/c-mo-realizar-un-pedido-xel... http://stoopball.ning.com/profiles/blogs/hydrochlorothiazide-12-5mg-en-l... http://writeskills.ning.com/profiles/blogs/clomiphene-25-mg-en-ligne-bai... http://manchestercomixcollective.ning.com/profiles/blogs/achat-rapide-ci... http://property.ning.com/profiles/blogs/farmacia-online-donde-comprar-ge... http://newmediavault.ning.com/profiles/blogs/clomipramina-comprar-en-far...

http://isladepascua.ning.com/profiles/blogs/c-mo-realizar-un-pedido-felo... http://newsmediaimages.ning.com/profiles/blogs/low-price-cabaser-0-25-mg... http://recampus.ning.com/profiles/blogs/donde-se-puede-comprar-generico-... http://thehiphophub.ning.com/profiles/blogs/losartan-50-mg-comprar-en-un... http://fotoathena.ning.com/profiles/blogs/comprar-generico-oftight-oflox... http://writeskills.ning.com/profiles/blogs/comprar-olmesartan-urgente-pu... http://153.126.169.73/GaijinConcierge/index.php?qa=31225&qa_1=leflunomid... http://www.facecool.com/profiles/blogs/oxybutynine-5mg-en-ligne-moins-ch... http://playit4ward-sanantonio.ning.com/profiles/blogs/buy-tetracyn-250mg... http://libertyattendancecenter1969.ning.com/profiles/blogs/donde-a-la-or... http://lorealprofessionnelbest.ning.com/profiles/blogs/generique-protopi... http://shamrockballerz.ning.com/profiles/blogs/farmacia-online-donde-com... http://www.q-voice.tv/old/redirect/test/qa/index.php?qa=77896&qa_1=achat... http://europe-ecologie-aube.ning.com/profiles/blogs/roxithromycin-150mg-... http://higgs-tours.ning.com/profiles/blogs/order-cosy-10mg-online-buy-co... http://whazzup-u.com/profiles/blogs/kann-ich-glucotrol-xl-glipizid-5-mg-... http://europe-ecologie-aube.ning.com/profiles/blogs/aerogra-sildenafil-c... http://mcspartners.ning.com/profiles/blogs/bon-plan-achat-nitrofurantoin... http://whozwholive.ning.com/profiles/blogs/felodipina-plendil-5mg-onde-c... http://www.facecool.com/profiles/blogs/salmeterol-0-025-mg-livraison-dis... http://libertyattendancecenter1969.ning.com/profiles/blogs/super-p-force...

http://isladepascua.ning.com/profiles/blogs/c-mo-realizar-un-pedido-felo... http://newsmediaimages.ning.com/profiles/blogs/low-price-cabaser-0-25-mg... http://recampus.ning.com/profiles/blogs/donde-se-puede-comprar-generico-... http://thehiphophub.ning.com/profiles/blogs/losartan-50-mg-comprar-en-un... http://fotoathena.ning.com/profiles/blogs/comprar-generico-oftight-oflox... http://writeskills.ning.com/profiles/blogs/comprar-olmesartan-urgente-pu... http://153.126.169.73/GaijinConcierge/index.php?qa=31225&qa_1=leflunomid... http://www.facecool.com/profiles/blogs/oxybutynine-5mg-en-ligne-moins-ch... http://playit4ward-sanantonio.ning.com/profiles/blogs/buy-tetracyn-250mg... http://libertyattendancecenter1969.ning.com/profiles/blogs/donde-a-la-or... http://lorealprofessionnelbest.ning.com/profiles/blogs/generique-protopi... http://shamrockballerz.ning.com/profiles/blogs/farmacia-online-donde-com... http://www.q-voice.tv/old/redirect/test/qa/index.php?qa=77896&qa_1=achat... http://europe-ecologie-aube.ning.com/profiles/blogs/roxithromycin-150mg-... http://higgs-tours.ning.com/profiles/blogs/order-cosy-10mg-online-buy-co... http://whazzup-u.com/profiles/blogs/kann-ich-glucotrol-xl-glipizid-5-mg-... http://europe-ecologie-aube.ning.com/profiles/blogs/aerogra-sildenafil-c... http://mcspartners.ning.com/profiles/blogs/bon-plan-achat-nitrofurantoin... http://whozwholive.ning.com/profiles/blogs/felodipina-plendil-5mg-onde-c... http://www.facecool.com/profiles/blogs/salmeterol-0-025-mg-livraison-dis... http://libertyattendancecenter1969.ning.com/profiles/blogs/super-p-force...

do you need a prescription for viagra
[url=http://viagrawithoutdoctorhnbmfdf.com ]viagra without a doctor prescription walmart [/url]
viagra without a prescription
viagra without doctor prescription
generic viagra without a doctor prescription

do you need a prescription for viagra
[url=http://viagrawithoutdoctorhnbmfdf.com ]viagra without a doctor prescription walmart [/url]
viagra without a prescription
viagra without doctor prescription
generic viagra without a doctor prescription

do you need a prescription for viagra
[url=http://viagrawithoutdoctorjwqa.com ]viagra without a doctor prescription [/url]
polk circuit judge dennis maloney
viagra without doctor prescription judpharmacy
online doctor

do you need a prescription for viagra
[url=http://viagrawithoutdoctorjwqa.com ]viagra without a doctor prescription [/url]
polk circuit judge dennis maloney
viagra without doctor prescription judpharmacy
online doctor

do you need a prescription for viagra
[url=http://viagrawithoutdoctorhnbmfdf.com ]viagra without a doctor prescription [/url]
online prescriptions
viagra without doctor prescription
viagra without a doctor prescription usa

do you need a prescription for viagra
[url=http://viagrawithoutdoctorhnbmfdf.com ]viagra without a doctor prescription [/url]
online prescriptions
viagra without doctor prescription
viagra without a doctor prescription usa

generic viagra without subscription walmart
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription [/url]
viagra without doctor prescription
viagra without a doctor prescription walmart
meds online without doctor prescription

no prescription viagra
[url=http://viagrawithoutdoctorjwqa.com ]100mg viagra without a doctor prescription [/url]
how to get viagra
viagra without doctor prescription
sildenafil without a doctor's prescription

no prescription viagra
[url=http://viagrawithoutdoctorjwqa.com ]100mg viagra without a doctor prescription [/url]
how to get viagra
viagra without doctor prescription
sildenafil without a doctor's prescription

viagra without prescription
[url=http://viagrawithoutdoctorjwqa.com ]generic viagra without a doctor prescription [/url]
viagra without a doctor prescription walmart
generic viagra without a doctor prescription
generic viagra without subscription

ed meds online without doctor prescription
[url=http://viagradoctorskllr.com ]100mg viagra without a doctor prescription [/url]
online doctors that provide prescriptions
viagra without a doctor prescription
levitra without a doctor prescription

ed meds online without doctor prescription
[url=http://viagradoctorskllr.com ]100mg viagra without a doctor prescription [/url]
online doctors that provide prescriptions
viagra without a doctor prescription
levitra without a doctor prescription

online doctors that provide prescriptions
[url=http://viagradoctorskllr.com ]100mg viagra without a doctor prescription [/url]
generic viagra without a doctor prescription
viagra without doctor prescription
cialis without doctor prescription

online doctors that provide prescriptions
[url=http://viagradoctorskllr.com ]100mg viagra without a doctor prescription [/url]
generic viagra without a doctor prescription
viagra without doctor prescription
cialis without doctor prescription

best generic viagra websites
[url=http://viagranbdnr.com ]generic viagra without a doctor prescription [/url]
viagra without a doctor prescription
generic viagra without a doctor prescription
viagra prescriptions over internet

viagra prescriptions over internet
[url=http://viagranbdnr.com ]generic viagra without a doctor prescription [/url]
viagra without a doctor prescription walmart
generic viagra without a doctor prescription
generic viagra without a doctor prescription

juzgados del condado de polk
[url=http://viagradoctorskllr.com ]generic viagra without a doctor prescription [/url]
100mg viagra without a doctor prescription
viagra without a doctor prescription
online doctors prescriptions

juzgados del condado de polk
[url=http://viagradoctorskllr.com ]generic viagra without a doctor prescription [/url]
100mg viagra without a doctor prescription
viagra without a doctor prescription
online doctors prescriptions

buy medication without an rx
[url=http://viagranbdnr.com ]viagra without a doctor prescription [/url]
generic viagra without subscription
viagra without doctor prescription
buy generic viagra - judpharmacy

online prescriptions
[url=http://viagradoctorskllr.com ]generic viagra without a doctor prescription [/url]
polk circuit judge dennis maloney
100mg viagra without a doctor prescription
viagra prescriptions over internet

prescriptions online
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription judpharmacy [/url]
viagra without prescription
viagra without doctor prescription
calhoun county courthouse

prescriptions online
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription judpharmacy [/url]
viagra without prescription
viagra without doctor prescription
calhoun county courthouse

buy generic viagra - judpharmacy
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription [/url]
county judge reinaldo ojeda
100mg viagra without a doctor prescription
where to buy viagra

buy generic viagra - judpharmacy
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription [/url]
county judge reinaldo ojeda
100mg viagra without a doctor prescription
where to buy viagra

generic viagra without subscription
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription judpharmacy [/url]
calhoun county courthouse
100mg viagra without a doctor prescription
viagra without doctor prescription

generic viagra without subscription
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription judpharmacy [/url]
calhoun county courthouse
100mg viagra without a doctor prescription
viagra without doctor prescription

best generic viagra websites
[url=http://viagrawithoutdoctorjwqa.com ]viagra without a doctor prescription walmart [/url]
sildenafil without a doctor's prescription
viagra without doctor prescription judpharmacy
generic viagra without subscription walmart

best generic viagra websites
[url=http://viagrawithoutdoctorjwqa.com ]viagra without a doctor prescription walmart [/url]
sildenafil without a doctor's prescription
viagra without doctor prescription judpharmacy
generic viagra without subscription walmart

buy generic viagra - judpharmacy
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription judpharmacy [/url]
real viagra without a doctor prescription
100mg viagra without a doctor prescription
calhoun county courthouse

buy generic viagra - judpharmacy
[url=http://viagrawithoutdoctorjwqa.com ]viagra without doctor prescription judpharmacy [/url]
real viagra without a doctor prescription
100mg viagra without a doctor prescription
calhoun county courthouse

Pages

Add new comment