Created
August 5, 2018 02:16
-
-
Save imbolc/0119a71ec68424ef1bbef386dc19427a to your computer and use it in GitHub Desktop.
Set target="_blank" attribute for all the external links
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 () { | |
// target="_blank" for external links | |
var origin = location.host.replace(/www\./, '') | |
Array.prototype.slice.call(document.getElementsByTagName('a')) | |
.filter(function (a) { return a.host && !a.host.match(origin + '$') }) | |
.forEach(function (a) { a.setAttribute('target', '_blank') }) | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment