Created
August 28, 2015 09:02
-
-
Save blogjunkie/29ff2ec80260ff037d07 to your computer and use it in GitHub Desktop.
Open external links in new window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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