Ever wanted to detect links on your site that point to other domains? A few times in the past I've had requests to be able to pick out all the hyperlinks from a site that move a user to a different domain.
The code below checks starts with a click event on all anchor links. It then pulls out the hyperlink reference and checks whether it matches the current documents domain. If the destination of the link points to a different domain then you have a block of code that is performed when the user clicks on the link.
var href = $(this).attr('href');
if ((href.match(/^https?\:/i)) && (!href.match(document.domain)))
var extLink = href.replace(/^https?\:\/\//i, '');
alert('clicked external link');
Pretty simple, but it allows you to amend the link with a custom message, or track it in any way you want.