document.onreadystatechange = function () { document.querySelectorAll("a").forEach((element) => { let href = element.href; if(href.indexOf(location.hostname) === -1){ element.target = "_blank"; element.setAttribute("rel", "noreferrer"); } }); }