Last active
November 17, 2016 15:10
-
-
Save ottonet/a0fc172e85b0355b2d50 to your computer and use it in GitHub Desktop.
Automatically add target="_blank" to external links with jQuery
This file contains hidden or 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