Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

How to read a text file in JavaScript?

following code is working fine for me
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tempFile = fso.OpenTextFile(fname, 1);
var line = tempFile.ReadLine();


but it is showing a security message that

An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?
[Yes] [No]

Following code is also not working
var text = '';
var filechar;
netscape.security.PrivilegeManager.enablePrivilege('UniversalFileAccess'); 
var file = new java.io.File(fname);
var FileReader = new java.io.FileReader(file);
filechar = FileReader.read();
while (filechar != -1) {
text = text + String.fromCharCode(filechar);
filechar = FileReader.read();
}
FileReader.close();
alert(text);


it is showing following error on line number 3.
Microsoft JScript runtime error: 'netscape' is undefined

Can anyone has a working solution without any problem?

Thanks in advance
-Amol
Posted
Updated 21-Jun-11 20:40pm
v4
Comments
thatraja 22-Jun-11 1:44am    
/*it is showing an error on line number 3.*/
what error? include that in your question.
Amol_27101982, India 22-Jun-11 2:58am    
Updated my question... Please let me know if you have anything related.

Thanks,
Amol
[no name] 22-Jun-11 1:59am    
What error on Line 3 ?
Amol_27101982, India 22-Jun-11 2:58am    
Updated my question... Please let me know if you have anything related.

Thanks,
Amol
Ankur\m/ 22-Jun-11 2:09am    
http://stackoverflow.com/questions/6410625/enable-and-popup-blocker-in-ie/6410887#6410887

1 solution

See this thread[^] for the reason why you will always require user permission.

Cheers,
Peter
 
Share this answer
 
Comments
Amol_27101982, India 22-Jun-11 5:31am    
Thanks for reply.
Can we define those user permission in the java script code itself ?? so that the popup will not appear...??

Please let me know.

Thanks,
-Amol
Peter_in_2780 22-Jun-11 5:37am    
Short answer - no. It's all about security.
Amol_27101982, India 23-Jun-11 1:16am    
Thanks Peter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900