-
-
Save iluwQaa/3daca0a1fcaae76f47c9c0d90134764b to your computer and use it in GitHub Desktop.
Automatically add target="_blank" to external links with jQuery
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(document.links).filter(function() { | |
return !this.target; | |
}).filter(function() { | |
return this.hostname !== window.location.hostname; | |
}).filter(function() { | |
return this.hostname != /javascript:/.test(this.hostname); | |
}).attr('target', '_blank'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment