![]() |
What is the best way to include another html file?
Hi,
What is the best way to include another html file such as a footer that is the same on all pages. I read about using a server side include, but is there a better way to do it? Thanks, Alan |
No, server side includes is the best way - have a look at using PHP includes.
|
Hi,
Will a server side include when viewing a file locally in a web browser? Thanks, Alan |
To use PHP it need to be running on a server for it to work. For local testing you can use something like xampp. This lets you install a server on your PC.
|
Hi,
I'm trying to use: Code:
<!--#include virtual="hello.htm" -->Code:
<p>hello</p>I've also tried installing iis7 and creating a virtual directory to it and browsing via that but it also does not work. Any ideas? Thanks, Alan |
Are you running this on xampp? It requires the file that contains the #include to have the .shtml extension - otherwise it won't work.
|
web pages that use server side includes need to have a .shtml extension unless you override it in a server configuration file (I'm not sure which file it is for IIS). You also need to be referencing the page via IIS and not directly for the include to work.
|
Hi,
I'm trying it with the webserver built into win7, iis7. Is there no easy way to import another html that doesn't have so many requirements? Thanks, Alan |
There is no way to include files without some sort of server side processing which mreans running a server in order for it to work.
Most web sites end up needing other server side processing in addition to includes and so a server side language such as PHP which supports both processing on the server and includes is a more flexible option than using SSI. The simplest way to set up a server on your own computer including both a server side language and a database (for storing data on the server after processing) is to download and install XAMPP - http://www.apachefriends.org/en/xampp.html The best alternative is to set up with a server/language/database combination that is at least similar to what you have on your live web hosting - even if the versions of each are not completely identical (although it is better if they are as then you know what works on your computer will still work when you upload it). |
Best method using what the other users have posted above mine.
You can use a iframe but they are very old and kind of useless when it comes to including main features of a website. Best way to go is with PHP or Javascript. |
Hi,
Thanks for all the help everyone, I'll check out xampp. Alan |
Hi,
I got it working with xampp - what other differences are there between file extensions? Should I use .shtml for every page or just ones with includes in them? Thanks, Alan |
Quote:
|
Quote:
If you use that extension for all your pages then the pages that don't have includes will load slightly slower because the server has to check if they have includes in them before sending them to the browser. The advantage that might offset this is that it allows you to add includes into a page that doesn't yet have them without having to rename the file. |
I wrote an article that included a simple way to incorporate a simple footer using Javascript and innerHTML. See if it will be sufficient in your case:
http://iphonedevlog.wordpress.com/20...gn-techniques/ Look at the "Footer content" section for full working code. Unfortunately, it isn't good for already existing entire HTML pages. |
| All times are GMT +1. The time now is 02:04 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.