PDA

Click to See Complete Forum and Search --> : HTML: Importing HTML from another file


Electroman
Jul 6th, 2003, 07:54 AM
Is it possible, and if so how, to insert html into my html document like how this statement works for stylesheets??
<LINK href="StyleSheet.css" type="text/css" rel="stylesheet">

The problem is I have a section of HTML code that is the same in every page and if I want to change it it would mean going thro every file and changing each file. My thort of the solution would be if I could put this repeated code in a seprate file then in all my other files I would put something like the satement above to import it.
Any ideas??

Thanx

RealisticGraphics
Jul 6th, 2003, 08:40 AM
To the best of my knowledge. The <LINK> Tag is largely ignored by most browsers with the exception of the CSS.

With ASP you could just include the file but if you do not have ASP access, you might find the below exceptable for your needs.

I use the following JavaScript method extensively on an Intranet I develope that has now server side access.

Create your JavaScript File (MyHeader.js):


document.writeln("<table border=\"0\" cellspacing=\"4%\" cellpadding=\"5\">");
document.writeln("<tr>");
document.writeln("<td align=\"center\" bgcolor=\"#00D9FF\"><b><a href=\"http://www.RealisticGraphics.com\">Realistic Graphics</a></b></td>");
document.writeln("<td align=\"center\" bgcolor=\"#00D9FF\"><b><a href=\"http://www.VBForums.com\">VBForums</a></b></td>");
document.writeln("<td align=\"center\" bgcolor=\"#00D9FF\"><b><a href=\"http://www.google.com\">Google</a></b></td>");
document.writeln("</tr>");
document.writeln("</table>");
document.writeln("<br>");


Create your HTML File (MyPage.htm):


<script language="JavaScript" src="MyHeader.js"></script>
Welcome to my JS Header Example. The above HTML was imported to this page.


Hope this helps.

Electroman
Jul 6th, 2003, 08:43 AM
Thanx, thats great!

RealisticGraphics
Jul 6th, 2003, 09:04 AM
No problem, yell if you need anything else.

DeadEyes
Jul 11th, 2003, 01:09 PM
what about IFRAMES

<iframe id="ifrmcontents" name="ifrmcontents" src="mypage.html" frameborder="0">

RealisticGraphics
Jul 11th, 2003, 09:07 PM
You could but it's not the same thing. Some versions of IE will display the iframe differently and some browsers won't display it at all.

DeadEyes
Jul 12th, 2003, 07:09 AM
typical, that's the most annoying thing about web development.

Electroman
Jul 17th, 2003, 05:56 AM
I had tried IFrames but the thing is I was trying to insert the HTML into a table and when I used IFrames it messed up the layout. No worries anyway its sorted now, mind I couldn't get it to work using .vbs/.vb files instead.