HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptCritical

Include another HTML file in a HTML file

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
includefileanotherhtml

Problem

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:



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

How can we do it in *.html file?

Solution

In my opinion the best solution uses jQuery:

a.html:

 
   
     
     
    $(function(){
      $("#includedContent").load("b.html"); 
    });
     
   

   
     
   


b.html:

This is my include file


This method is a simple and clean solution to my problem.

The jQuery .load() documentation is here.

Code Snippets

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

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>
<p>This is my include file</p>

Context

Stack Overflow Q#8988855, score: 844

Revisions (0)

No revisions yet.