Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include html file in html using html5 [duplicate]

Tags:

html

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).

like image 715
lolo Avatar asked Jan 25 '12 10:01

lolo


People also ask

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

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


2 Answers

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.

like image 179
greenoldman Avatar answered Sep 28 '22 04:09

greenoldman


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

like image 45
Tor Valamo Avatar answered Sep 28 '22 04:09

Tor Valamo