tags:

views:

63

answers:

4

a.html

ABC

b.html

    <!--#include FILE="a.html" --> 

XYZ

access b.html: file:///home/kurz/Desktop/b.html

it only shows XYZ

is this not the way to include files in html?

A: 

If it's apache try

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

From here:

include virtual and include file do almost the same thing. The difference is that include virtual takes a URL-style path, which is what you probably expect. include virtual can also execute CGI programs, if your web server supports that, and include their output. include file takes a file-system path, and cannot execute CGI programs. Both also accept relative paths, so for a simple case like the above they work the same. If you don't understand the difference between web paths and file system paths, use include virtual.

Preet Sangha
+7  A: 

What you're attempting is called a Server-Side Include (SSI). As such, it requires the pages be running on a webserver, rather than a local file.

When you're requesting the page from a server, the server sees the <!--#include FILE="a.html" --> preprocessor and performs the SSI.

When you're referencing it directly from your filesystem, such as file:///home/kurz/Desktop/b.html, all your browser is doing is loading the raw html and interpreting that.

Alastair Pitts
Not only does it need to run on a webserver, the server has to support SSI and be configured to look for SSI directives in the page being viewed.
David Dorward
A: 

The one you are doing is SSI -> Server Side Includes which requires Apache or IIS to work.

You need to install Apache (for windows / unix) or IIS (for windows) for this to work. Also, you can test this on remote webservers.

Ruel
A: 

Yes, servers are required for server side includes

If its just plain HTML, use iframes... instead of a #include, use :

<iframe src="a.html"></iframe>

If your site is to be XHTML compliant (probably not).. you would need to make further changes

Ravindra Sane
iframes are as much as part of XHTML as they are HTML
David Dorward