Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Javascript Write command with contents of a text file

Posted on 2000-03-13
Last Modified: 2013-11-18
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:


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

Thank you.
Question by:Stoke

Accepted Solution

jkunal earned 100 total points
ID: 2611662


Expert Comment

ID: 2611708
why you not use the include file
<!--#include file="test.htm"-->
LVL 19

Expert Comment

ID: 2611709
You could also use Server Side Includes

eg <!--#include file="../cgi-bin/textfile.txt"-->

Expert Comment

ID: 2612125
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">
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.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question