I want to include HTML to an other HTML with a script, which I get from another website. This script works great if the HTML files are in the same folder, but if I want to include a HTML file from subfolder it does not loading it. And my question is why it does not work?
The HTML file to include is in /main folder named navbar.html. And the HTML which needs to get the other is in /main/subfolder. I am going one folder back using "../".
The script is:
w3.includeHTML = function(cb) {
var z, i, elmnt, file, xhttp;
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
file = elmnt.getAttribute("w3-include-html");
if (file) {
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
elmnt.innerHTML = this.responseText;
elmnt.removeAttribute("w3-include-html");
w3.includeHTML(cb);
}
}
xhttp.open("GET", file, true);
xhttp.send();
return;
}
}
if (cb) cb();
};
And this is the HTML to get:
<!-- Navigation -->
<div w3-include-html="../navbar.html"></div>
<script>
w3.includeHTML();
</script>
<!-- /Navigation -->