Created
January 7, 2022 18:25
-
-
Save wouldhide/d858524c76d71ed2bc7df31ec09e98ac to your computer and use it in GitHub Desktop.
Add target='_blank' to all external links on a page
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
for(var c = document.getElementsByTagName("a"), a = 0; a < c.length; a++) { | |
var b = c[a]; | |
b.getAttribute("href") && b.hostname !== location.hostname && (b.target = "_blank") && (b.target = "_blank") && b.classList.add("external-link"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment