1 2/*https://www.w3schools.com/howto/howto_html_include.asp*/ 3function includeHTML() { 4 var z, i, elmnt, file, xhttp; 5 /*loop through a collection of all HTML elements:*/ 6 z = document.getElementsByTagName("*"); 7 for (i = 0; i < z.length; i++) { 8 elmnt = z[i]; 9 /*search for elements with a certain attribute:*/ 10 file = elmnt.getAttribute("include-html"); 11 if (file) { 12 /*make an HTTP request using the attribute value as the file name:*/ 13 xhttp = new XMLHttpRequest(); 14 xhttp.onreadystatechange = function() { 15 if (this.readyState == 4) { 16 if (this.status == 200) {elmnt.innerHTML = this.responseText;} 17 if (this.status == 404) {elmnt.innerHTML = "Page not found.";} 18 /*remove the attribute, and call this function once more:*/ 19 elmnt.removeAttribute("w3-include-html"); 20 includeHTML(); 21 } 22 } 23 xhttp.open("GET", file, true); 24 xhttp.send(); 25 /*exit the function:*/ 26 return; 27 } 28 } 29};