Created
December 26, 2024 13:22
-
-
Save aydgn/fcfd4d8bf08b56b738dcd224308eba44 to your computer and use it in GitHub Desktop.
open-external-links-in-new-tab.js
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
| const links = document.querySelectorAll("a"); | |
| links.forEach(link => { | |
| if (!link.href.startsWith(window.location.origin)) { | |
| link.setAttribute("rel", "nofollow noopener noreferrer"); | |
| link.setAttribute("target", "_blank"); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment