Link to home
Start Free TrialLog in
Avatar of Stoke
Stoke

asked on

Javascript Write command with contents of a text file

I am writing a set of HTML pages which all have common information at the bottom of a page, which is updated regularly. I don't want to change every page, so I thought that it would be a good idea if all the pages could look up a text file with the common html in it. To do this I thought the write command would be the best option:

document.write(/cgi-bin/TEXTFILE.TXT);

This isn't working. Does anyone have an idea the best way to reach my goal?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of jkunal
jkunal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FRehman
FRehman

why you not use the include file
<!--#include file="test.htm"-->
You could also use Server Side Includes

eg <!--#include file="../cgi-bin/textfile.txt"-->
You can't write a file like that in client side javascript.  Unless you have access to server side javascript, the solution would have to be a javascript include file...
<SCRIPT language="JavaScript" src="/cgi-bin/textfile.js">
</SCRIPT>
notice that it ends in .js

Then the contents of the file has to be javascript code.  You could just have a series of document.write()s in it, like this:

document.write('This is the first line of the footer');
document.write('This is the second line of the footer');

Updating may be a little more difficult since you have to deal with those pesky doucment.writes and watch out for single quotes in your strings...  but this should for you.


-Josh