Equivalent of include() in HTML

Viewed 35752

I was wondering wether there is a way to include some html content inside another html using only html?

A replacement to PHP's

<?php include("file.php"); ?>

Is this possible?

EDIT:

This has brought up some confusion, what I needed was "almost an html tag" that had the functionality of including a html document in another.

11 Answers

Have you tried:

<object type="text/html" data="file.html"></object>

Almost 10 years later, some people may still have doubts about this. So I'm going to explain a simple solution that we have today in 2020.

I always use the jquery .load() function and never had a problem with that.

Exemple: ( "#content" ).load( "includes/menu.html" );

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!

Related