-
-
Save kylefox/63bfd3ba2d1d0d1a5bbb to your computer and use it in GitHub Desktop.
For those "external links should open in new tabs" clients…
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
// Array.forEach potentially faster than loop | |
// http://jsperf.com/testing-foreach-vs-for-loop | |
var links = document.querySelectorAll('a[href*="//' + window.location.host +'"]'); | |
[].slice.call(links).forEach(function(a) { | |
a.target = '_blank'; | |
}); |
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
var a = document.querySelectorAll('a[href*="//' + window.location.host +'"]'), | |
length = a.length; | |
for(var i = 0; i < length; ++i) { | |
a[i].target = '_blank'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment