Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


common html part

Posted on 2003-03-06
Medium Priority
Last Modified: 2013-12-16
Hi Expert

I'm writing several HTML pages. Each page has a part of  code which is same for all the pages. I would like to put this code to a separate file and include it in each page. So, any change on this common file will be reflect on all these pages.

What's the good way to do it?

Question by:zouwei

Expert Comment

ID: 8086036
You can write them in a js file and then include them in every page.

e.g. you write the code in the js file and name it header.js

so in ur code u can put:

<script src="header.js"></script>

They are only for javascript format but you can easily use the document.write() to write out html.

Expert Comment

ID: 8086199
Well if you have the possibility to use ASP or some other server side language, then do it server side. You can include lots of js-files with HTML in them to your page, but it really isn't the wisest or fastest way. What if the user has disabled client scripting? Your page never even renders properly.

When you do things in server side, then you have total control over what your page renders out. You can even do browser sniffer and render the page differently for every browser.
LVL 63

Accepted Solution

Zvonko earned 300 total points
ID: 8086223

It depends on your web server.
The server has to support SSI.
This stands for ServerSideIncludes.
And this is the tag to be used:
 <!--#include file="/includes/common.shtml"-->

Here some description:

If your server has no SSI enabled, then you could try this:
<iframe src="="/includes/common.html"></iframe>

Or this:
<OBJECT DATA="http://www.experts-exchange.com" HEIGHT="400" WIDTH="500"></OBJECT>

Good luck,

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 17

Expert Comment

ID: 8087950

Expert Comment

ID: 8089544
I've run into a similar issue.  You can put the code into a .js and run it externally, but then you'll be cutting off the population who use non js capable browsers.  This isn't a problem in most circumstances, but might be depending on your situation.

What I've done in those circumstances, is create a template file with the code 100%.  Then use that template to create all the pages in the site.

I've then used Allaire Homesite 4 (now Macromedia Homesite 5, or this functionality is also in Macromedia Dreamweaver MX) to search and replace multiple lines of code through multiple files, directories, etc.  It works quite well.  The downside is that you'll have to FTP all the pages back up to the server, which isn't usually a big deal unless you have a large site you're working with.
LVL 17

Expert Comment

ID: 8089874
Note that search engines are part of the population which doesn't handle JavaScript, so if you have your navigation included with JS then they won't be able to follow the links in it (and therefore won't index the pages behind it)

Author Comment

ID: 8103340
Thanks. I solve this issue using asp include.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question