import 'normalize.css/normalize.min.css'; import './styles/app.css'; document.addEventListener("readystatechange", event => { if(event.target.readyState === 'complete') { initExternalLinks(); } }); function initExternalLinks() { document.querySelectorAll('a').forEach(elem => { if(isExternalURL(elem.getAttribute('href'))) { elem.setAttribute('target', '_blank'); } }) } const isExternalURL = (url) => { if(url.startsWith('/')) return false; return new URL(url).origin !== location.origin; }