/ Published in: jQuery

This code appends a class of external to all all outbound links
It includes a fix for Safari which does not recognise internal links that use a different port
It includes a fix for Safari which does not recognise internal links that use a different port
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function() { $('#extlinks a').filter(function() { return this.hostname && this.hostname.split(":")[0] !== location.hostname.split(":")[0]; }).addClass('externalLink'); }); //css .externalLink { background:url(/myiconpath/myicon.gif) top left no-repeat; // set background position to suit your needs padding: 15px 0 0 0; // set padding to width of icon plus the size of gap you would like }
URL: http://www.learningjquery.com/2008/08/quick-tip-dynamically-add-an-icon-for-external-links
Comments
