Skip to content

Instantly share code, notes, and snippets.

@kmgdevelopment
Created January 16, 2014 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmgdevelopment/8447370 to your computer and use it in GitHub Desktop.
Save kmgdevelopment/8447370 to your computer and use it in GitHub Desktop.
open all links in new tab
$('a').each(function() {
// get this site's URL
var a = new RegExp('/' + window.location.host + '/');
// check if the link is an actual web link
if(this.href.match(/^http/)){
// check if the link contains this site's URL
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