6
0
Fork 0
3D-Druck_Landingpage/themes/hugo-theme-flat/static/js/href_handling.js

20 lines
742 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);
2024-01-09 13:24:44 +01:00
element.classList.add("internal");
2024-01-09 13:05:30 +01:00
}else {
element.setAttribute("target", "_blank");
2024-01-09 13:24:44 +01:00
element.classList.add("external");
2024-01-09 13:05:30 +01:00
}
})
});