Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q498 Do you know of anyway to retrieve data from a .txt file located on the server?

You are here: irt.org | FAQ | JavaScript | File | Q498 [ previous next ]

No, Client Side JavaScript cannot read text files. One solution is to hold the data in a hidden form field and then read the contents for the form field:

<form name="myform">
<input name="myText" type="hidden" value="<b>Hello World</b>">
</FORM>

<script language="JavaScript"><!--
alert(document.myform.myText.value);
//--></script>

The following was submitted by Kevin Hatfield

Use the 'ondownload' behavior in DHTML. It works with jscript to download any text file into a variable, as long as the file is on the same domain. (Or you could use the File System Object by calling vbscript from jscript)

This example is from the MSDN library. The variable "s" contains the contents of the file "download.htm" (It doesn't have to be done in-line. You can assign the behavior using script as well)

<HTML XMLNS:IE>

<SCRIPT>
 function onDownloadDone(s) { alert (s); }
</SCRIPT>

<IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" />
<P>Click <A HREF="javascript:oDownload.startDownload('download.htm', onDownloadDone)">here</A> to begin downloading this page.

©2018 Martin Webb