website/js/includeHTML.js

19 lines
644 B
JavaScript
Raw Normal View History

2021-03-24 22:18:55 +01:00
let z = document.getElementsByTagName("*");
2021-01-11 20:13:12 +01:00
2021-03-24 22:18:55 +01:00
for (let i = 0; i < z.length; i++) {
let element = z[i];
let externalFileURL = element.getAttribute("includeHTML");
2021-01-12 09:48:32 +01:00
if (externalFileURL) {
2021-03-24 22:18:55 +01:00
let xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) { element.innerHTML = this.responseText; }
if (this.status == 404) { element.innerHTML = "Page not found."; }
element.removeAttribute("includeHTML");
}
}
xhr.open("GET", externalFileURL, true);
xhr.send();
}
}