Good day I tried to add an HTML snippet I created to another full HTML file But the js script of the html snippet didn't import. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Good day I tried to add an HTML snippet I created to another full HTML file But the js script of the html snippet didn't import.

Any alternatives for importation??

18th Jun 2020, 10:48 AM
Fawaz Bello
Fawaz Bello - avatar
6 Answers
+ 1
have any code to share ? so we can get the better image of the problem and what you're trying to do
18th Jun 2020, 11:11 AM
Taste
Taste - avatar
+ 1
you're creating an infinite loop right there by calling includeHTML() again after making a request. remove that and you're good. other than that, make sure to call includeHTML the first time after the page load. window load listener, or calling it at the very bottom of the body. i tested it myself the code are working correctly aside what i describe above. pretty neat concept btw good job
18th Jun 2020, 11:44 AM
Taste
Taste - avatar
0
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; } } }
18th Jun 2020, 11:18 AM
Fawaz Bello
Fawaz Bello - avatar
0
<div w3-include-html="Nav.html"></div>
18th Jun 2020, 11:18 AM
Fawaz Bello
Fawaz Bello - avatar
0
Nav.html <h1>Recipe-world</h1> </div> <div id="img"> <div id=lines> &#9776; </div> <div id="lnk"><input type="search" id="inp" value="recipe for" /></div> <div id= "pages" > <div id="lnk" ><a href="#">recipe for </a><br /></div> <div id="lnk" > <a href="#">recipe for a food </a><br /></div> <div id="lnk" ><a href="#">recipe for</a><br /></div> <div id="lnk" > <a href="#">recipe for </a><br /></div> <div id="lnk" > <a href="#">recipe for </a><br /></div> <div id="lnk" > <a href="#">recipe for </a><br /></div> <div id="lnk" ><a href="#">recipe for </a><br /></div> <div id="lnk" > <a href="#">recipe for </a><br /></div> <div id="lnk" > <a href="#">recipe for </a><br /></div> <div id="lnk"><a href="#">recipe for </a><br /></div> <div id="lnk" ><a
18th Jun 2020, 11:19 AM
Fawaz Bello
Fawaz Bello - avatar
0
The nav.html js won't work when exported
18th Jun 2020, 11:22 AM
Fawaz Bello
Fawaz Bello - avatar