Skip to content

Instantly share code, notes, and snippets.

View ubermichael's full-sized avatar

Michael Joyce ubermichael

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ubermichael on github.
  • I am ubermichael (https://keybase.io/ubermichael) on keybase.
  • I have a public key ASAjm4-rj1faxQCbVfkmiP5lkSRekgClKpG5wOO1mihjbwo

To claim this, I am signing this object:

@ubermichael
ubermichael / gist:6323890
Created August 23, 2013 20:53
Open all external links in a new window/tab. Scan all the links in an HTML document, and add target="_blank" to any that go to a different domain.
$(function(){
var hostname = window.location.hostname.replace('www.', '');
$('a').each(function(){
var link_host = $(this).attr('hostname').replace('www.', '');
if(link_host !== hostname) {
$(this).attr('target', '_blank');
}
});
});