I was wondering wether there is a way to include some html content inside another html using only html?
A replacement to PHP\'s
the only thing would be an iframe which is pure html. but you also can use javascript to get the page via ajax and include it into your dom hirarchy
The lack of Include\Import in Html is really frustrating!
A good alternative is "Server Side Includes (SSI)" in case "PHP" is not supported!
SSI is supported by almost any (if not all) web host server!
<!--#include virtual="layout.html" -->
The file that contains the above line must end with ".shtml" or ".shtm" extensions!
It's really annoying that something as easy as Include\Import can't be performed by the browser itself!
Like php or Node.js, preprocessing the html using Javascript itself before the HTML Load process start should be supported in any browser!
Have you tried:
<object type="text/html" data="file.html"></object>
Yes there is but you need to enable it in your config or .htaccess:
Options +Includes
AddType text/html .shtml
AddHandler server-parsed .shtml
Of course with that youd need to rename any file doing the including to .shtml
... or you could jsut use:
Options +Includes
AddType text/html .html
AddHandler server-parsed .html
the syntax itself is similar to comment:
<!--#include virtual="/footer.html" -->
Shameless plug of a library that I wrote the solve this.
https://github.com/LexmarkWeb/csi.js
<div data-include="/path/to/include.html"></div>
The above will take the contents of /path/to/include.html
and replace the div
with it.