I have multiple HTML pages saved locally on my computer.
a.html, b.html, c.html, etc. etc.
I want a.html to be able to use the code that I have in the other HTML documents.
Here is my code:
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 atrribute:*/
file = elmnt.getAttribute("w3-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 have been using this code to combine multiple HTML documents together that i run them all locally on my computer. My code does not run online and does not use an external server. It used to work fine until I updated firefox. Now I get an error message:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///home/josh/Desktop/test/test.html. (Reason: CORS request not http).
I did some research and apparently it has something to do with a security flaw in firefox. I found a work-around for it by changing: privacy_file_unique_origin to false in firefox's about:config page. But for me this is not ideal.
I am looking for a way to fix this issue without having to compromise the security of my computer.
How do i properly satisfy the cors request?
or is there a better way to combine multiple html documents?
I am trying to keep the code HTML and javascript.
Also please dumb down the answer as much as possible.