Created
October 7, 2017 16:16
-
-
Save proprietary/e840bcdfa554474bf4b95acf129c7c29 to your computer and use it in GitHub Desktop.
open all external links in new window
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
(function() { | |
var urlHostname = function(url) { | |
var a = document.createElement('a') | |
a.href = url | |
return a.hostname | |
} | |
var reProtocol = /https?/, l = document.links | |
for (var idx = 0; idx < l.length; ++idx) { | |
if (urlHostname(l[idx].href) !== window.location.hostname && reProtocol.test(l[idx].href)) { | |
l[idx].setAttribute('target', '_blank') | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment