What\'s the best way to open all external links (URLs that don\'t match the current domain) in a new tab using JavaScript, without using jQuery?
Here\'s the jQuery I
Pure JS:
function externalLinks() { 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") } } ; externalLinks();