Skip to content

Instantly share code, notes, and snippets.

@gpassarelli
Created March 20, 2012 12:47
Show Gist options
  • Save gpassarelli/2134931 to your computer and use it in GitHub Desktop.
Save gpassarelli/2134931 to your computer and use it in GitHub Desktop.
jQuery: Open External Links In New Window
$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment