tags:

views:

51

answers:

3

I want to call one html page fron another in a div.

I tried using

<include file="NavigationTree.html" />

and

<? include("/starfix/pages/NavigationTree.html"); ?>

But it doesn't work. Am I doing something wrong or do i need to do it some other way?

A: 

You can use an iframe for that, e.g.:

<iframe width="500" height="300" frameborder="no" scrolling="no" marginheight="0"   marginwidth="0" 
src="http://www.example.com/page.html"&gt;&lt;/iframe&gt;
RegDwight
This is handy but has downsides: It won't share the DOM with the outlying document, and most importantly, it can't resize automatically to fit the iframed page's content.
Pekka
+5  A: 

You may want to consider using Server Side Includes (SSI).

You would place your HTML snippet into a separate file, such as NavigationTree.html, and then you would simply reference it in your web pages by using:

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

SSI is supported by all the popular web servers, including Apache, IIS and lighttpd.


Note that if you are using a shared host, you may have to use the .shtml, .stm, or .shtm extension for SSI to work. If you have root access to your web server, it can be easily configured to enable SSI for any extension, including html.

Daniel Vassallo
+1 this beats the PHP approach if it works in pages with the `.html` extension. And even if it doesn't, it is better to add `html` files to the list of SSI file types than to the list of file types that get parsed by PHP.
Pekka
+1  A: 

This is not possible in pure HTML.

The former is a notation I have never seen before, it is not HTML, maybe it works in some specific server-side templating language.

The latter is PHP. It should work but you need to bear in mind include() works with absolute paths inside the server's file system.

You should specify a relative path:

<? include("./NavigationTree.html"); // will work if it's in the same directory ?>

or an absolute one that will probably look something like this:

<? include("/path/to/your/www/dir/starfix/pages/NavigationTree.html"); ?>

(ask your admin for the absolute path to your web root)

You can maybe also do a HTTP include:

but that's unwise because it tends to be slow, and generates a second request on each page request.

You can also use SSI as outlined by @Daniel.

Pekka
Not putting a path *won't* look in the current directory. It will force PHP to muck through `include_path` looking for the include. Usually `.` is in it, but if this is not the case then the include won't be found, or the wrong include will be used. It's best to always put an explicit path, such as `./NavigationTree.html` instead.
Ignacio Vazquez-Abrams
@Ignacio you're right. I'll add that info.
Pekka