Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Last active March 23, 2016 14:04
Show Gist options
  • Save bastianallgeier/786bf00b9fa1262709f4 to your computer and use it in GitHub Desktop.
Save bastianallgeier/786bf00b9fa1262709f4 to your computer and use it in GitHub Desktop.
For those "external links should open in new tabs" clients…
$('a').each(function() {
if(this.host !== window.location.host) {
$(this).attr('target', '_blank');
}
});
var a = document.querySelectorAll('a');
for(var i = 0; i < a.length; ++i) {
if(a[i].host !== window.location.host) {
a[i].target = '_blank';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment