0

I have two html files first.html and second.html and I want to include the second file into the first file for code re usability. I am using following statement to include the file:

<link rel="import" href="html file name here">

But it is not working. I tried using another solutions too, but none of them worked.

So give any suggestion.

dingo_d
  • 11,160
  • 11
  • 73
  • 132
Dhiraj
  • 870
  • 2
  • 12
  • 25
  • Possible duplicate of [Include another HTML file in a HTML file](https://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file) – Heretic Monkey Oct 15 '19 at 16:47

4 Answers4

1

Using jQuery:

a.html:

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

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

b.html:

<p> This is my second file </p>
Kaushik Maheta
  • 1,741
  • 1
  • 18
  • 27
1

Look at this website. http://www.html5rocks.com/en/tutorials/webcomponents/imports/

It suggest what are the best practices. It always depends on your real needs. Why you didn't use frames?

Matteo Defanti
  • 212
  • 1
  • 5
  • 17
0

use jquery's .load() function to load your template. Please refer this documentation. http://api.jquery.com/load/

Mahesh
  • 1,427
  • 2
  • 19
  • 42
0

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. http://api.jquery.com/load/

Source: Include another HTML file in a HTML file Google is your friend :)

Community
  • 1
  • 1