/ Published in: jQuery

Detects all external/outgoing links, adds class, & adds target = _blank. When using a strict doctype, this method is valid when using target manipulation.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('#wrapper a:not(.popupwindow)').filter(function() { var theHref = this; if (theHref.hostname && theHref.hostname !== location.hostname) { $(theHref).not(".noAutoIcon").addClass("external"); $(theHref).not(".noAutoLink").attr('target','_blank').bind('click keypress', function(event) { var code=event.charCode || event.keyCode; if (!code || (code && code == 13)) { if(pageTracker){ var fixedLink = this.href; fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1"); fixedLink = '/outgoing/' + fixedLink; pageTracker._trackPageview(fixedLink); }; }; }); }; });
Comments
