View Full Version : I can't read these txt file,using the File Object

02-05-2004, 04:26 AM
Hi there.I need to get some information from a txt file that I'm using as a simple database,but I have not succeed so far.
Can you tell me what is wrong in these function?I consulted the File Object manual,but I think everything is fine!

function open_file()
var x;
var info = new File("filename.txt");
x = info.readln();
<input type="button" name="search_button" onClick="open_file()" value="search">

02-05-2004, 04:52 AM
Javascript can't read the contents of a text file without ActiveX and IE or XMLHTTP (http://www.codingforums.com/showthread.php?s=&threadid=30449&highlight=XMLHTTP).

var fso = new ActiveXObject('Scripting.FileSystemObject');

For more details of FSO, click this (http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject.html). It's VBScript but the methods and properties are the same, just follow the camelCasing convention of property and method names.

02-05-2004, 06:34 AM
Well I have a sorta cheesy method that works: you simply have a iframe in a div were the visibility is hidden. You then set the url of the iframe to the text file and get the innerHTML of the iframe. Of course this will not work over different domains.