Reading contents of a text file using JavaScript throwing error

Posted by vix on Stack Overflow See other posts from Stack Overflow or by vix
Published on 2010-02-06T07:44:10Z Indexed on 2010/05/29 2:52 UTC
Read the original article Hit count: 281

Filed under:
|

I'm using the following code to read the content of a text file using javascript. But when I'm getting an alert message which says "An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?" When I click on yes nothing is happening.

I'm using IE 6.0

function ieReadFile(filename)  
{ 
    try 
    { 
        var fso  = new ActiveXObject("Scripting.FileSystemObject");  
        var fh = fso.OpenTextFile(filename,1);  
        var contents = fh.ReadAll();  
        fh.Close();

        alert(contents);
        //return contents; 
    } 
    catch (Exception) 
    { 
        return "Cannot open file :("; 
    } 
} 

Can anyone please help me resolve this issue?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html