Email conversation
From | John Robinson |
To | Me |
Subject | is a HTML subroutine possible |
Date | 25 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.
From | Me |
To | John Robinson |
Subject | Re: is a HTML subroutine possible |
Date | 27 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/
From | John Robinson |
To | Me |
Subject | Re: is a HTML subroutine possible |
Date | 27 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.
From | Me |
To | John Robinson |
Subject | Re: is a HTML subroutine possible |
Date | 27 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>