PDA

View Full Version : Including files with Javascript


Torus
08-13-2003, 12:05 PM
Basic question, but still important...

I'm working on a nav bar that needs to be included on every page of my site. I would like to write one file that I can include in each page - that way, changes would only be made to the one file, instead of to every page on the site.

So how do I include a javascript file? Is there any way to include html files as well (the nav bar is layed out using a table)?

Thanks,

Torus

Torus
08-13-2003, 01:59 PM
Ok, I did more poking around and I figured out how to include .js files in my code.

Now, how can I include HTML without server side scripting? Is there a way to layout, say, a navigation bar, with the javascript file I include?

:confused:
Help would be appreciated.

Thanks,

Torus

Dennis
08-13-2003, 02:27 PM
Originally posted by Torus

Now, how can I include HTML without server side scripting?


the answer is no.

but you can do something similar.

you call from the page a external js file

<script src="file.js">


in this file, you write so:

document.write('<html><head>...</head>')
document.write('<body>...</body></html>')


this is a pseudo-include...

you should do more document.writes, this is the only way... :)

if you must include also scripts, you should do so:

document.write('<scr'+'ipt>')


if you write document.write('<script')

the browser understand something else :)

Moonglobe
08-22-2003, 09:21 PM
if you're on Apache you can do <!--#include virtual="path/to/inluded/file" --> (i THINK that's the syntax