Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access and read a local file from html+javascript page running locally

I would like to write a small html file that would run locally and manipulate a small text file on my computer. My requirements are:

  • Text file sits in a directory on my computer (test.txt)
  • Html file is in the same directory as the text file (test.html)
  • I would like to use javascript in the html to read and write the text file.

Is this possible at all? If yes, how do I read and write my text file using javascript?

like image 995
gyurisc Avatar asked Jun 18 '11 15:06

gyurisc


1 Answers

Normally, it is not possible and would be a security issue.
How ever, if you use some plugins (ActiveX, FF extensions etc) they may enable you to do so.
There is also the subject of local storage you can use with the most newer browsers.

From your comments, I am wondering why not using PHP/Ruby any other server side language to do so? They are tailored just for that.

like image 125
Itay Moav -Malimovka Avatar answered Sep 23 '22 02:09

Itay Moav -Malimovka