lolo lolo - 4 months ago 13
HTML Question

Include another HTML file in a HTML file

I have 2 HTML files, suppose

a.html
and
b.html
. In
a.html
I want to include
b.html
.

In JSF I can do it like that:

<ui:include src="b.xhtml" />


It means that inside
a.xhtml
file, I can include
b.xhtml
.

How can we do it in
*.html
file?

Answer

In my opinion the best solution is:

Using jQuery:

a.html:

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#includedContent").load("b.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

b.html:

<p> This is my include file </p>

Like that i can get a simple and clean solution to my problem. Documentation