Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | File | Q498 [ previous next ]

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

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.

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.