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

Q19 How do I read data from an input file?

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

Andre De Bruin writes:

  1. There is a method to read a file in Netscape Navigator (through the Java class)
  2. Depending on what you want to do with the file, this me be a solution:
    1. create a separate (invisible) frame
    2. use parent.FRAMENAME.location = "yourfile.htm" to load the file in that frame
    3. The file is loaded, you can not read the lines from within Javascript (but you can read all the hrefs and anchors
    4. there are no security violations when the file is on the same host (and path?) as the loading file.
    5. very kinky is to have javascript in that file that is being loaded, code that is activated with an onLoad()
    6. Even more kinky is to have the loaded file after doing whatever work it needed to do, perform a document.location = "anotherfile.htm" ON ITS OWN FRAME. I used this method to make a search application with "unlimited" data input: the loaded scripts output their data to a common frame.

Shyamala k. writes:

To read and write into a flat file use Jscript's ActiveXobject.

Greg Lewis writes:

There is a way in netscape to do this and I am sure Internet explorer can also. Below I have code that can read any file on the clients machine, but only with their approval. This code only works on Netscape:

<script language="JavaScript"><!--
function readFromFile(filename) {
  var text = '';
  var filechar;
  netscape.security.PrivilegeManager.enablePrivilege('UniversalFileAccess');
  var file = new java.io.File(filename);
  var FileReader = new java.io.FileReader(file);
  filechar = FileReader.read();
  while (filechar != -1) {
    text = text + String.fromCharCode(filechar);
    filechar = FileReader.read();
  }
  FileReader.close();
  return text;
}

alert(readFromFile('test.txt'));
//--></script>

Feedback on 'Q19 How do I read data from an input file?'

©2018 Martin Webb