0

I want user upon clicking a button it will load the a txt file from a e.g Desktop and display the contents.

Can this be done?

I found a lot of examples for loading a file but not displaying it.

Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
perumal316
  • 1,119
  • 6
  • 17
  • 35

3 Answers3

2

JavaScript in the browser can't access the user's file system - it would be a security issue.

  1. Consider other client side options like Java Applets or Flash.
  2. In the worst-case, you could upload the file to the server and send it back to the client - but there's probably no usecase that calls for such an expensive hack.

Additionally, check out this SO question - the File API will allow this.

Community
  • 1
  • 1
no.good.at.coding
  • 19,923
  • 2
  • 58
  • 51
1

Try this http://codesnippets.joyent.com/posts/show/602

Jayantha Lal Sirisena
  • 20,846
  • 10
  • 70
  • 92
0

There's an excellent tutorial on html5rocks.com, 'Reading Files in JavaScript using the File APIs', that shows how to use the FileReader interface:

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Richard C
  • 501
  • 5
  • 5