// This code selects all links that are not on the current domain and adds the 'target="_blank"' attribute
var externalLinks = document.querySelectorAll('a[href^="http://"], a[href^="https://"]');
for (var i = 0; i < externalLinks.length; i++) {
if (externalLinks[i].hostname !== window.location.hostname) {
externalLinks[i].setAttribute('target', '_blank');
}
}