dcsimg
www.webdeveloper.com
Results 1 to 8 of 8

Thread: How can I use common code on multiple web pages?

  1. #1
    Join Date
    Jan 2010
    Posts
    23

    How can I use common code on multiple web pages?

    I have about 20 html pages that will all share some common html coding. The common elements will be changed and updated frequently.

    Is there an easy way to have 1 document that contains the common code that is used by all 20 pages so I don't need to updated all of the pages each time?

    Also, I want to stay away from frames.

    Thanks, Damon

  2. #2
    Join Date
    Jan 2010
    Posts
    13
    try this using php:
    save the common code in a temp.php and include it wherever you need in your webpage using the include command

  3. #3
    Join Date
    Feb 2010
    Location
    India
    Posts
    9
    As I understand ,

    The best solution to your problem is using php.

    Just separate header,sidebars,mainbody,and footer section in different pages...

    and put it in the pages by using include_once or require_once command.

    We are using this process in all our projects and it can be implemented easily and successfully..

    Best OF LUck

  4. #4
    Join Date
    Aug 2009
    Posts
    84
    a historical note:

    Long time ago (before PHP and other scripting languages became popular), people used M4 macro processor to include common elements into HTML pages. A nice article describing the process:

    http://www.linuxjournal.com/article/2393

  5. #5
    Join Date
    Dec 2009
    Location
    Italy
    Posts
    82
    I just posted about here

    http://www.webdeveloper.com/forum/sh...71#post1068271


    have a look

  6. #6
    Join Date
    Jan 2010
    Posts
    23
    Thanks for the replies. I'll check out these methods and try them on my website.

  7. #7
    Join Date
    Oct 2007
    Location
    Western Massachusetts, USA
    Posts
    387
    Try using an external Javascript file. For help on how to do that, check out the Javascript forum here. Basically:
    <script src="somefile.js" type="text/javascript" langauge="javascript"></script>

  8. #8
    Join Date
    Feb 2010
    Posts
    21
    Nikiitea was right but he didn't explain it. Here's a quick explanation:

    Step 1. Rename all your .html pages to .php
    Step 2. Open notepad and paste the common html into a document.
    Step 3. Save the common html document as your_title.php
    Step 4. Open the 20 HTML pages and paste this code in the spot where you want the common code to appear:

    <?PHP include("http://yourwebsiteurl.com/your_title.php"); ?>

    Now when you make changes to the your_title.php file, it will update all your pages.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles