Skip to content

Instantly share code, notes, and snippets.

@therealkevinard
Created January 25, 2018 16:27
Show Gist options
  • Save therealkevinard/f90d0be4ddf50fceaee1a342869c369a to your computer and use it in GitHub Desktop.
Save therealkevinard/f90d0be4ddf50fceaee1a342869c369a to your computer and use it in GitHub Desktop.
Open all external links in new tab
jQuery('a').map(function (i, el) {
var elem = $(el);
var href = elem.attr('href');
var host = window.location.host;
if (href.indexOf(host) < 0 && href.indexOf('http') > -1) {
elem.attr('target', '_blank');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment