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.

5
  • Not possible. The user has to at least select the file in an <input type="file" /> element. Commented Oct 10, 2014 at 11:35
  • @Sirko can't we specify the file name and its location instead in the JS? Commented Oct 10, 2014 at 11:36
  • 4
    If you could do it completely automatic, you could read any content from a user's harddrive: passwords, private files, ... If you need "permanent" storage on a client's computer look at cookies and localStorage. Commented Oct 10, 2014 at 11:38
  • @Sirko How to look into localStorage? Commented Oct 10, 2014 at 11:42
  • localStorage@MDN. Commented Oct 10, 2014 at 11:43

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Be careful, because this will only work in Internet Explorer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.