website/assets/js/page.js

23 lines
619 B
JavaScript
Raw Normal View History

2021-08-05 13:51:44 +02:00
document.addEventListener("readystatechange", event => {
if(event.target.readyState === 'complete') {
initOverflow();
initExternalLinks();
}
});
function initOverflow() {
let body = document.querySelector('body');
if (body.scrollHeight > window.outerHeight) {
body.style.height = 'auto';
}
}
function initExternalLinks() {
document.querySelectorAll('a').forEach(elem => {
if(isExternalURL(elem.getAttribute('href'))) {
elem.setAttribute('target', '_blank');
}
})
}
const isExternalURL = (url) => new URL(url).origin !== location.origin;