Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading text files with javascript

paulnightingale
Guest
 
Posts: n/a
#1: Apr 3 '06
Hi
I've got a ticker tape that is written in Java Script 1.2 which
displays text that has to be currently changed in the program code.
What I want to do is to find the bit of javascript to get the program
to read a text file so that the text file can be used to update the
contents of the ticker tape. Preferably I will produce a bit of code
that produces a window in which you type the text you want to display
and then this gets saved as a text file, but firstly I need to get my
ticker tape program to read a text file for the content of the ticker
tape. If you have any suggestions on how to do this they would be much
appreciated.

Cheers

Paul




Julian Turner
Guest
 
Posts: n/a
#2: Apr 3 '06

re: Reading text files with javascript



paulnightingale wrote:
[color=blue]
> Hi
> I've got a ticker tape that is written in Java Script 1.2 which
> displays text that has to be currently changed in the program code.
> What I want to do is to find the bit of javascript to get the program
> to read a text file so that the text file can be used to update the
> contents of the ticker tape. Preferably I will produce a bit of code
> that produces a window in which you type the text you want to display
> and then this gets saved as a text file, but firstly I need to get my
> ticker tape program to read a text file for the content of the ticker
> tape. If you have any suggestions on how to do this they would be much
> appreciated.
>
> Cheers
>
> Paul[/color]

Hi

This question has probably been answered a few times on this and other
news groups, so it is worth doing some searching on this news group or
<URL:http://www.webdeveloper.com/forum/forumdisplay.php?s=&daysprune=30&forumid=3>.
[color=blue]
>From my amateur knowledge, reading a text file may be achived through[/color]
the following (depending on security settings):-

1. XMLHttpRequest object

If you set the URL to a local file name, you can access the contents
through the "responseText" property.

This is probably the most cross-browser method.

2. Active X - "Scripting.FileSystemObject"

This is an ActiveX object provided by Microsoft. It is only available
for browsers which support ActiveX, and have the
"Scripting.FileSystemObject" object installed on the client.

As far as I am aware you should find that "Scripting.FileSystemObject"
is commonly already installed on Windows clients.

Example:-

var FSO = new ActiveXObject("Scripting.FileSystemObject");
var nForReading=1;
var oFileObj = FSO.OpenTextFile(sFileName,nForReading, false);
var sFileContents=oFileObj.ReadAll();
oFileObj.Close();

3. XPCOM - Firefox Only

Firefox has XPCOM components. See an example for reading a file at the
bottom of the following page:-

<URL:http://www.captain.at/programming/xul/>

Regards

Julian Turner

Closed Thread