c3re-website/themes/hugo-theme-flat/static/js/href_handling.js

18 lines
656 B
JavaScript
Raw Normal View History

2024-01-09 13:05:30 +01:00
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll('a').forEach(function(element) {
const myhost = window.location.hostname;
const linkhost=new URL(element.href).hostname;
if(myhost === linkhost) {
let prefetchUrl=new URL(element.href).toString()
// lest make a prefetch tag for this url
let link = document.createElement('link');
link.setAttribute('rel', 'prefetch');
link.setAttribute('href', prefetchUrl);
link.setAttribute('as', 'document');
document.head.appendChild(link);
}else {
element.setAttribute("target", "_blank");
}
})
});