Last active
September 8, 2016 09:11
-
-
Save martinwheeler/e00a8b0d3f9352bbc092b4802c527137 to your computer and use it in GitHub Desktop.
Add target _blank to all URLs which are external
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
jQuery('a').each(function() { | |
var url = jQuery(this).attr('href'); | |
var httpRegex = new RegExp('https?:\/\/', 'i'); | |
if (url.toLowerCase().indexOf(window.location.hostname) == -1 && httpRegex.test(url)) { | |
jQuery(this).attr('target', '_blank'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment