John Robinson

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJohn Robinson
ToMe
Subjectis a HTML subroutine possible
Date25 January 2007 13:38
What a terrific site, amazing. Most of it way beyond me!

I have a web site with many hundreds of pages each with a part of each page
with the same section of text and links. This small section of info
periodically needs changing.

Question: is it possible to call a separate file of text/links info and
display that info within a space on an existing web page, thereby only
needing to change one file each time the text and links need changing.
Instead of changing hundreds of pages with same changes

I have limited technical expertise in this field. Thanx for any help in
advance.

John Robinson.
FromMe
ToJohn Robinson
SubjectRe: is a HTML subroutine possible
Date27 January 2007 10:28
John,

> Question: is it possible to call a separate file of text/links info
> and display that info within a space on an existing web page

Yes, but ...

You need to have some form of server side scripting support for this.
Personally I know how to use PHP or SSI for this, both of which are usually
available if you are hosted on Apache.

With PHP (check with your hosting service if PHP is enabled - typically you
will have to call your files .php instead of .html), there are two normal
ways; require, and include. These are used like this:

<?php include('../foo.php'); ?>

The difference between them is that if include fails, the rest of the page
will still be sent to the browser. If require fails, it is a fatal error,
and the browser will not be sent the rest of the page. In both cases, the
included page is also treated as a PHP page, so any PHP inside it will also
be executed. (Warning, XML prologs will confuse it if your server has PHP
shorttags enabled.)

With SSI, you need to have the Apache includes feature enabled. Typically
this means putting this in your Apache configuration file, or in a .htaccess
file in your web page's / directory:

Options +Includes
AddHandler server-parsed .html

Then you put this inside the HTML files where you want to include another
file:

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

Note that using PHP may screw with your server's "last modified"
information, so browsers may not cache pages so well (meaning higher
bandwidth use), and SSI does not work well with GZip encoding (meaning for
some sites it has to be disabled), so again, you may use more bandwidth.

There is a third alternative, but I warn you against using it for important
navigation, as it causes significant accessibility problems. HTML has the
iframe element that can include another page inside a frame within the
current page. It is not supported by some browsers, particularly those for
people with certain disabilities. It allows you to specify fallback content,
but this can be an annoying approach. However, if you want to use this:

<p>
  <iframe src="morelinks.html" height="100" width="200">
    <a href="morelinks.html">More links</a>
  </iframe>
</p>


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJohn Robinson
ToMe
SubjectRe: is a HTML subroutine possible
Date27 January 2007 19:30
Thanx for response.

I have tried :

<iframe name="myIframe" src="anotherfile.html" height="170"width="600"
  border="0" frameborder="0"></iframe>

to call anotherfile.html to display text/links in the 170x600 window and it
seems to work ok.

What do you think?

John.
FromMe
ToJohn Robinson
SubjectRe: is a HTML subroutine possible
Date27 January 2007 19:42
John,

> <iframe name="myIframe" src="anotherfile.html" height="170"width="600"
>   border="0" frameborder="0"></iframe>
>
> What do you think?

If it is possible for you to use the server side processing, I recommend you
go for that approach instead; just about every server side language will
have a proper way to do this - it is not just limited to PHP or SSI as I
showed, you can also do it with ASP, JSP, etc, etc.

If you are going to go down the iframe road (which I recommend against),
please make sure you include fallback content for browsers that cannot
display inline frames:

<iframe name="myIframe" src="anotherfile.html" height="170" width="600"
border="0" frameborder="0"><a href="anotherfile.html">More links ...</a>
</iframe>
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.