Forum Moderators: open

Message Too Old, No Replies

including HTML like you can with javascript

         

jonplackett

12:51 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



i've only recently started using javascript and html properly (used to just use dreamweaver)

but i was wondering, is it possible to include a separate part of html as an include, like you can with javascript where you have a script source in another file?

i'm trying to make a menu system that is editable from just one file and then refered to in the html of all the pages in the site so i only have to edit it once for the whole site to be updated.

thanks

mm1220

1:00 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld jonplackett!

To address your question:
What you want to do can be achieved in one of three (popular) ways, using:

1) Frames
2) Server Side Includes
3) PHP Includes (very similar to 2)

Can you tell us if your webhost allows you to use PHP or SSI?

No.1 involves only html but can get messy/complicated.
I'm not going to advocate it!

No.2 involves giving all your files the extension .shtml and putting the following snippet of code where your menu code normally goes:

<!--#include virtual="menu.inc" -->

where menu.inc contains the html for the menu bar.

No.3 involves giving all your files the extension .php
and putting the following snippet of code into your files in the appropriate place:

<?php
include("menu.inc");
?>

Note that changing the extensions is not strictly necessary it depends on your particular web server's configuration but the above is common.

[edited by: mm1220 at 1:09 pm (utc) on Dec. 4, 2004]

jonplackett

1:05 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



unfortunately not no.

mm1220

1:13 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



It appears then that frames are your best bet!
Although if you are trying to get more of an understanding of web development I'd highly recommend getting some cheap (~$5 pm) web hosting with support for php.

Anybody want to help out with frames? (I gladly haven't touched them yet this millenium!)

jonplackett

2:57 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



thanks very much. i have been warned off using frames by a few people. i will look into php and ssi support a bit more.

ta

rainborick

3:10 pm on Dec 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are reasons to avoid regular frames, but there is a way to include HTML from an external file using the <iframe> tag (which some people often erroneously confuse with conventional frames).

An <iframe> will insert the contents of an external file into your HTML document. It is cross-browser compatible and does not rely on JavaScript or server support services like SSI or PHP. <iframe>s are not subject to most of the issues that people associate with conventional frames because they are very different concepts. Check it out on any HTML tutorial site and I'm sure you'll find uses for it. Good luck!