tags:

views:

134

answers:

6

How can I include an HTML file in another HTML file. Is there any simple way to do that?

Thanks

A: 

Well if you have any server-side scripting language available all will perform fine at this task. Another option would be html-frames (in your case most likely an iframe), or ajax (asynchrounus javascript request).

HalloDu
I'm using javascript. Can you give details on those?
Ravi
Are you using a specific library like jquery or prototype or just plain javascript?
HalloDu
+1  A: 

You might be looking for information on iframes (live example).

<html>
<body>

<iframe src ="/default.asp" width="100%" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>

</body>
</html>
voyager
A: 

My preferred method employs PHP, if that is installed on your server. If so, the simplest way to do it is just insert this code at the appropriate place in your containing file: <?php include('filename.php') ?>

Note that both files must have the extension .php.

Scott Cranfill
+2  A: 

Are you serving the HTML files from a web server like IIS or Apache? Both support server-side includes:

<!--#include virtual="nameOfFileToInclude.html" -->

A page at the WWW FAQs explains.

Dour High Arch
A: 

You could use server side includes (ie. Apache SSI doc).

Frames would be the only other way I can think of which would not require the usage of a programming language on either the server or client side.

TheClair
+4  A: 

I think you're looking for server side includes: http://en.wikipedia.org/wiki/Server_Side_Includes. To summarize (and oversimplify) change the extension of your page from .html page to .shtml, then you should be able to use an include statement similar to:

<!--#include virtual="somefile.html" -->

Paul