Skip to content

Instantly share code, notes, and snippets.

@celsowhite
Last active October 13, 2020 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celsowhite/ef9e25e1592c210944979af5ef0cef55 to your computer and use it in GitHub Desktop.
Save celsowhite/ef9e25e1592c210944979af5ef0cef55 to your computer and use it in GitHub Desktop.
Link external links to a new window.
/*-------------------------
Target Blank
---
Link all external links to a new window.
-------------------------*/
document.addEventListener('DOMContentLoaded', () => {
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');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment