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?
HTML Iframe SyntaxThe HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With