Skip to content

Instantly share code, notes, and snippets.

@blogjunkie
Created August 28, 2015 09:02
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 blogjunkie/29ff2ec80260ff037d07 to your computer and use it in GitHub Desktop.
Save blogjunkie/29ff2ec80260ff037d07 to your computer and use it in GitHub Desktop.
Open external links in new window
/**
* Open all external links in a new window
*/
jQuery(document).ready(function($) {
$('a').not('[href*="mailto:"]').each(function () {
var isInternalLink = new RegExp('/' + window.location.host + '/');
if ( ! isInternalLink.test(this.href) ) {
$(this).attr('target', '_blank');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment