I am using W3-Schools "include-html" https://www.w3schools.com/howto/howto_html_include.asp
It states that you can use multiple snippets. My plan was to include a header and a footer for each page by using this method.
On my index.html page I have this:
<!doctype html>
<html lang="en">
<!--Include Content-->
<script src="assets\scripts\include_content.js">
</script>
</head>
<body>
<header>
<div include-html="header.html"></div>
</header>
<footer>
<div include-html="footer.html"></div>
</footer>
<!--Scripts-->
<script>
includeHTML();
</script>
</body>
</html>
The scripts are a direct copy and paste from W3 (with minor changes to attribute names):
function includeHTML() {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain attribute:*/
file = elmnt.getAttribute("include-html");
if (file) {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4) {
if (this.status == 200) {
elmnt.innerHTML = this.responseText;
}
if (this.status == 404) {
elmnt.innerHTML = "Page not found.";
}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
};
xhttp.open("GET", file, true);
xhttp.send();
/* Exit the function: */
return;
}
}
}
I can get the footer to run if I delete the include-html="header.html" so I know the linking is there. But I can not get both footer and header to run.
Both footer and header pages are currently identical except for the message so I know where the message is coming from.
Can you see if I am missing something or why the second <div include-html="footer.html"></div>
is not working?