Last active
December 9, 2016 20:48
-
-
Save bgantick/9269e8a24e9423d06910be19c7f80d32 to your computer and use it in GitHub Desktop.
Open external links in a new tab/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
window.onload = function() { | |
var anchors = document.getElementsByTagName('a'); | |
var a = new RegExp('/' + window.location.host + '/'); | |
for (var i = 0; i < anchors.length; i++) { | |
if (!a.test(anchors[i])) { | |
anchors[i].setAttribute('target', '_blank'); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment