0

Could you please tell me whether there is any way of reading and displaying the value from the text file using Javascript when I open the HTML page?

The file is in the local system and it needs to be picked up automatically when the HTML page opens up and the result should be displayed in alert message as well as in the HTML page.

Sophia Sutter
  • 43
  • 1
  • 6

2 Answers2

2

See similar question, it is NOT possible to load local files using plain javascript.

However, we can use HTML5 file APIs to facilitate the loading of user specified files.

Community
  • 1
  • 1
0

I got the answer for this

   var fso = new ActiveXObject("Scripting.FileSystemObject");
  var ForReading = 1;
  var f1 = fso.OpenTextFile("c:\\file.txt", ForReading);
  var text = f1.ReadAll();
  f1.close();
  alert( text);

Thanks for your help

Sophia Sutter
  • 43
  • 1
  • 6