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?
using html 5 (if it can be done at all in html 5).
The HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.
Surprisingly, the same question was asked and it is possible: HTML5 include file
Rafa's answer:
Use the object tag:
<object name="foo" type="text/html" data="foo.inc"></object>
foo.inc should include valid HTML.
I tested it on Konqueror, Firefox and Chromium.
Note you must use a separate </object>
tag otherwise any content after it gets discarded.
If you find it useful (I do), please upvote Rafa answer (not mine) because "it is not possible" is spreading like disease.
If your server supports SSI (server side includes) you can put the following in your html-files without needing a scripting language or whatever. Apache has SSI enabled by default (I think?)
<!--#include file="same_path_file.html" -->
<!--#include virtual="docroot_file.html" -->
"file" is relative to the current file, and probably what you would use for including related files like "relevant_article_poll.html".
"virtual" is relative to document root (ie, your website root) and you would use it for including global files, like headers and footers.
Doesn't really matter which one you choose, but it's useful to know the difference between the two.
Also, the include directive makes a new internal http request to the server for each file, so you could include php files and the likes and they would be executed as they should.
Here's a useful overview of SSI: http://en.wikipedia.org/wiki/Server_Side_Includes
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