Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 473
lolo Avatar asked Jan 24 '12 14:01

lolo


People also ask

How do I display the content of one HTML page in another?

HTML Iframe SyntaxThe HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.

How do you reference another in HTML?

Linking in HTML code is done with the anchor tag, the <A> tag. The letter "A" in the tag is then followed by an attribute. For a link to another web page, the "A" is followed by "HREF". To set a bookmark in the same page, the "A" is followed by "NAME", which you'll see how to do later.


1 Answers

In my opinion the best solution uses 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> 

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

The jQuery .load() documentation is here.

like image 55
lolo Avatar answered Nov 13 '22 17:11

lolo