473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

linking multiple documents in html (not hyperlink !!)

Hi All,

Is there any way to link all the header and footer information from the main html(index.html) to all the pages, without actually typing them in all the pages.

I know this could be done in PHP but don't know in HTML.

As I have like 30 different HTML pages and each one has the same header and footer, and if i change something in index.HTML, then I have to change that in all the pages which is really frustrating.

Thanks for help

Kumar
Jul 25 '08 #1
5 1519
Brosert
57
Use PHP

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include("header.html");
  3. ?>
  4.  
.
Jul 25 '08 #2
oler1s
671 Expert 512MB
Is there any way to link all the header and footer information from the main html(index.html) to all the pages, without actually typing them in all the pages.
No, there isn’t. It’s frustrating, yes. Are you in a situation where you cannot use PHP or another language to combine the HTML document on the fly?

The two other options are to use Javascript and to use frames. Javascript makes you dependent on the client having JS enabled. If they don’t, you have a problem.

Frames bring their own problems, but at least all browsers support them as they are a part of HTML.
Jul 25 '08 #3
Thankyou so much for your suggestions.

Reply @ Brosert: If suppose I use the php to call the html header and footer, then do I need to have php installed in my computer or client computer who will visit my site and will it work in IE 5+, Firefox and Opera??


Reply @ oler1s: Regarding javascript, I am not very familar with that scripting language and futhermore as you suggested it will be browser dependend.
How to use frames in html page, that means if I use frames and can link it to other documents also??


Thanks for your reply
Kumar
Jul 25 '08 #4
Brosert
57
The PHP needs to be installed on the server that is hosting the web page - which if you're using a professional hosting service, it usually is!! - if you're using you're own server from home/work you would need to install it!

(Incedently, silly me didn't read that you weren't so interested in php solutions)
Jul 25 '08 #5
I had a similar problem... had to stick with html extention but include external file data. This is what worked for me... but of course it depends on Javascript.

This is the javascript, which in the example following is in a file called "include.js".

Expand|Select|Wrap|Line Numbers
  1. // for including file info
  2.  
  3. //load xml file
  4.  
  5. // code for IE
  6. if (window.ActiveXObject) {
  7.   xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  8.   xmlDoc.async=false;
  9.   xmlDoc.load(includeFile);
  10. }
  11. // code for Mozilla, Firefox, Opera, etc.
  12. else if (document.implementation && document.implementation.createDocument) {
  13.   xmlDoc=document.implementation.createDocument("","",null);
  14.   xmlDoc.load(includeFile);
  15. }
  16. else {
  17.   alert('Your browser cannot handle this script');
  18. }
  19.  
  20. function setInclude(tags) {
  21.   var ta=new Array();
  22.     var tt=new Array();
  23.     var ts=0, i;
  24.   ta=tags.split(' ');
  25.     ts=ta.join('');
  26.     ta=ts.split(',');
  27.   for(i=0; i < ta.length; i++) {
  28.       tt=ta[i].split('>');
  29.     document.getElementById(tt[1]).innerHTML=xmlDoc.getElementsByTagName(tt[0])[0].childNodes[0].nodeValue;
  30.     }
  31. }
  32.  

Another file contains the text and html for the headers etc... or anything that goes on a bunch of pages. For the example it is called "include.xml".

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <includes>
  3.  
  4. <header><![CDATA[
  5. stuff... html code and text
  6. <a href="stuff.html">stuff</a><br>
  7. <font color="red">end</font> of stuff
  8. ]]></header>
  9.  
  10. <footer><![CDATA[
  11. put all the html & text for the footer here
  12. ]]></footer>
  13.  
  14. </includes>
  15.  
For the example there are just 2 items, "header" and "footer".

You have to define where you want the header and footer on the web page, and you can do that like this,
Expand|Select|Wrap|Line Numbers
  1. <div id="top"></div>
  2. ....
  3. <div id="bottom"></div>
  4.  
I used a different name for the ID just to indicate that you can... it could also have been named "header" and "footer".

Next we have to add some code in the head section of the web pages like so,

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. var includeFile='/include.xml';
  3. </script>
  4. <script language="JavaScript" type="text/javascript" src="/include.js"></script>
  5.  
The second line defines the file with the stuff to be included.
The fourth line gets the javascript.

Finally, on each web page we also need a onLoad call, like so,

Expand|Select|Wrap|Line Numbers
  1. <body onload="setInclude('header>top, footer>bottom')">
  2.  
The body tag might of course contain other stuff, but here we make a call to "setInclude()". We pass to this function the names of the things in the xml file with the names of where they go in the web page div tags. For example here, the xml file stuff named "header" is sent to the div tag with the ID set to "top". That's what the ">" indicates. A comma and optional space separates each of these pairs. There can be as many pairs as needed. But if it's referenced in the setInclude then it needs to be defined in the web page with a unique ID and defined in the xml file also.

You can also make a transfer of something in the xml file to the web page via a onclick="setInclude('fromXMLitem>todivID')"

A thing I noticed is, if something on the page takes a long time to load, then the stuff that's supposed to be included will be a long time showing up... cuz the transfer can't happen till the load is done. But to get around that, you can put the slow-loading thing in the xml file instead of the web page, which will allow the page to get done loading quickly, and then bring the slow thing back to the web page with the onLoad call to setInclude().
Jul 25 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lori Bolen | last post by:
I was trying to research the best way to implement hyperlinks with multiple resources. We say we need links that allow multiple actions. What we mean is that when we click on a hyperlink, we...
2
by: sunil | last post by:
Hi, We have lot of c and fortran archive libraries that have complex dependencies. We have different server tasks that use some of these libraries. We have developed a tool inhouse that links...
4
by: Robert Oschler | last post by:
I have a web page that tracks clicks on certain hyperlinks. I am using attachEvent() to attach to the document onClick handler, for IE browsers. It works fine, except that for about 1 out of every...
3
by: Stephen Gray | last post by:
Hi, What I'm trying to do is produce a number of XML documents that can be linked together. For example say I had one document called "valuations.xml" which is a lists all of the...
6
by: theo.bruening | last post by:
Hello all. I hope someone can help me here. I need to make a db on many pictures, however, if I OLE them, the access database grows hugely. If I only hyperlink them, I can't view them. is there...
2
by: Boxer | last post by:
I really need help, well Im working on some prog in access 2K, and one part of it is a place to store some documents doc, xls, cdr, bmp. How can I put link to this files and with some button open...
4
navyguy59
by: navyguy59 | last post by:
I need to know if I make an Access database that utilizes the Get External Data function to draw data from multiple Excel documents, can I do something to auto-update the database to accept new...
3
by: Jordan S. | last post by:
I would appreciate your thoughts and opinions on the following: I am looking to render documents into multiple document formats. At a minimum the documents will need to be rendered as HTML, and...
4
by: naveenmurthy | last post by:
Hello All, I have created a .mht file in following format. 1. The .mht file contains following htmls. a. MHTLinkingProblem.html b. Left.html c. Right.html d. Start.html
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.