4

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?

1
  • 1
    ... "Call"? How, pray tell, did you do that? Commented May 11, 2010 at 9:58

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+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.
3

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:

<? include("http://www.example.com/starfix/pagesa/NavigationTree.html"); ?>

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.

1 Comment

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.
0

You could also use jQuery for this,

e.g.

<div id="yourDiv" />
<script> 
$("#yourDiv").load("NameOfYourPageToReadFrom.ext #NameOfDivToReadFrom");
</script>

This puts the contents of the 'NameOfDivToReadFrom' DIV in the called file ''NameOfYourPageToReadFrom' into the loaded DIV ('yourDiv') in your current file.

Remember to add the definition to the header part of your html.

e.g.

<head>
       <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head> 

Comments

-2

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"></iframe>

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.