html include

Solutions on MaxInterview for html include by the best coders in the world

showing results for - "html include"
Alice
25 Jan 2019
1//# https://www.w3schools.com/howto/howto_html_include.asp
2<div w3-include-html="content.html"></div>
3   <script>
4function includeHTML() {
5  var z, i, elmnt, file, xhttp;
6  
7   /* Loop through a collection of all HTML elements: */
8  z = 
9   document.getElementsByTagName("*");
10  for (i = 0; i < z.length; i++) 
11   {
12    elmnt = z[i];
13    /*search for elements with a certain atrribute:*/
14    file = 
15   elmnt.getAttribute("w3-include-html");
16    if (file) {
17      
18   /* Make an HTTP request using the attribute value as the file name: */
19      
20   xhttp = new XMLHttpRequest();
21      
22   xhttp.onreadystatechange = function() {
23        
24   if (this.readyState == 4) {
25          
26   if (this.status == 200) {elmnt.innerHTML = this.responseText;}
27          
28   if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
29          
30   /* Remove the attribute, and call this function once more: */
31          
32   elmnt.removeAttribute("w3-include-html");
33          
34   includeHTML();
35        }
36      
37   } 
38      xhttp.open("GET", file, true);
39      
40   xhttp.send();
41      /* Exit the function: */
42      
43   return;
44    }
45  }
46}
47</script>
Madeline
15 Feb 2016
1/* a.html: */
2
3<html> 
4  <head> 
5    <script src="jquery.js"></script> 
6    <script> 
7    $(function(){
8      $("#includedContent").load("b.html"); 
9    });
10    </script> 
11  </head> 
12
13  <body> 
14     <div id="includedContent"></div>
15  </body> 
16</html>
17/* b.html: */
18
19<p>This is my include file</p>
Nolann
19 Nov 2016
1<!-- a.html: -->
2
3<html> 
4  <head> 
5    <script src="jquery.js"></script> 
6    <script> 
7    $(function(){
8      $("#includedContent").load("b.html"); 
9    });
10    </script> 
11  </head> 
12
13  <body> 
14     <div id="includedContent"></div>
15  </body> 
16</html>
17<!-- b.html: -->
18
19<p>This is my include file</p>