Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    No, server side includes is the best way - have a look at using PHP includes.
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi,

    Will a server side include when viewing a file locally in a web browser?

    Thanks,

    Alan

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    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.
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi,

    I'm trying to use:

    Code:
    <!--#include virtual="hello.htm" -->
    With hello.html containing:

    Code:
    <p>hello</p>
    But I don't see it including it. I've tried various paths as well...

    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

  • #6
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    Are you running this on xampp? It requires the file that contains the #include to have the .shtml extension - otherwise it won't work.
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,607
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    New Coder
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,607
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    Regular Coder
    Join Date
    Jul 2012
    Location
    London
    Posts
    473
    Thanks
    4
    Thanked 86 Times in 86 Posts
    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.

  • #11
    New Coder
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for all the help everyone, I'll check out xampp.

    Alan

  • #12
    New Coder
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

  • #13
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,623
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    Quote Originally Posted by alank2 View Post
    Should I use .shtml for every page or just ones with includes in them?
    That’s entirely up to you. You can also have SHTML files with plain HTML in them (i. e. without includes), or keep the .htm/.html extension but if you have includes they have to be named .shtml (unless you change that in the server config, e. g. through an .htaccess file).

  • #14
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,607
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by alank2 View Post
    Should I use .shtml for every page or just ones with includes in them?
    There are advantages and disadvantages to both ways.

    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #15
    Regular Coder
    Join Date
    Jun 2011
    Location
    CA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    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.
    Last edited by StevenHu; 02-20-2013 at 06:09 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •