how to read text file using javascript

how do i read a text file using javascript activexobject
on local machine.
Who is Participating?
bpmurrayConnect With a Mentor Commented:
Only for IE - FireFox won't allow ActiveX:

function readit(fileName) {
   var data = "";
   var fileObj = new ActiveXObject("Scripting.FileSystemObject");
   if (fileObj.FileExists(fileName)) {
      var txtStream = fileObj.OpenTextFile(fileName,1);
      data = txtStream.ReadAll();
   return data;
clockwatcherConnect With a Mentor Commented:
Here's a cross-browser solution, but kind of pointless... if you're trying to serve up this webpage from an external website and expecting to be able to read a local file, security restrictions will prevent it - no matter what way you go.

<script language="javascript">
if (window.XMLHttpRequest) {    
      req = new XMLHttpRequest();    
else if (window.ActiveXObject) {    

      req = new ActiveXObject("Microsoft.XMLHTTP");    
}'GET', "file:///C:/test.txt");

req.onreadystatechange = function() {    
        if (req.readyState == 4) {    
} }

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.