Click to See Complete Forum and Search --> : Inlcuding HTML files from javascript?


JonathanDoe
04-01-2003, 03:14 PM
I was wondering if you can include HTML files from javascript?

I use something like this in HTML ,

<!--#include file="bottom.html"-->

Now I was wondering if I can call to include an HTML file from within javascript?

I've tried doing,

document.write('<!--#include file="bottom.html"-->');

But it seems like javascript realizes there is a comment,
beginning at (<!--) and then the rest of the line is in grey italics in ColdFusion studion (i.e. indicating it is a comment). so it seems like it doesnt recognize the end of comment (-->)
and right to the end of the line, including the ending semicolon is all commented out?

I'm wondering if this is an acceptable way of including files, but I am just missing something syntacitcally, or whether there is another way to do it? Any help would be greatly appreciated and solve many problems.

gil davis
04-01-2003, 03:28 PM
I've tried doing,

document.write('<!--#include file="bottom.html"-->');

But it seems like javascript realizes there is a comment,
beginning at (<!--) and then the rest of the line is in grey italics in ColdFusion studion (i.e. indicating it is a comment).Have you included that probably useless "hide the script from old browsers" crap?<script...>
<!-- hide from old browsers
...
//-->
</script>Hmm... I wonder what a browser will do when it sees "-->" somewhere in the script? ;)

Try it this way:document.write("&lt;!-- ... --&gt;");

JonathanDoe
04-01-2003, 03:39 PM
Ya I have included that little chunk of code, and that one line still seems to be commented out?...so I'm not sure how to include these files?

JonathanDoe
04-01-2003, 03:44 PM
Thanks for the suggestion, I tried the &gt; and &lt; but its seems to just write out

<!--#include file="bottom.html"-->

rahter than recognizing it as an html tag?

This is getting frustrating....

pyro
04-01-2003, 05:13 PM
Not sure if this will work but give it a try...

document.write('<!'+'--#include file="bottom.html"--'+'>');

gil davis
04-02-2003, 05:56 AM
The problem is that the INCLUDE is a server-side function, and the document.write is a client-side function. Once the file starts up at the client, it cannot use anything on the server. The SERVER has to read the INCLUDE, not the CLIENT.