I have an html page on my local filesystem and i want to use that to read a txt file in the same directory with the FileReader API. i tried using an iframe for this but chrome will block me from getting the text using the contentWindow property. is there any way to do this?
Asked
Active
Viewed 511 times
0
-
To improve the response you get from your questions, consider doing such things as posting a [minimal, complete and verifiable example](http://stackoverflow.com/help/mcve), [syntax highlighting](http://meta.stackexchange.com/questions/184108/what-is-syntax-highlighting-and-how-does-it-work), making your question clear in the title ,[adding necessary tags](http://stackoverflow.com/help/tagging)... and [heading on over to the FAQ](http://stackoverflow.com/help/how-to-ask) for more info – tinonetic Sep 01 '16 at 18:16
-
1I don't believe that this is possible. Here is a similar question: http://stackoverflow.com/questions/9473837/is-it-possible-to-load-a-file-with-js-html5-filereader-on-non-served-page – Erik Christianson Sep 01 '16 at 18:16
-
1If you were trying to write something like a native application with html/css/javascript you could look into electron: http://electron.atom.io/ – Erik Christianson Sep 01 '16 at 18:17
1 Answers
0
You can't read file without direct user interaction - through form input or drag and drop. What you can is make ajax request of this file or use jquery load.

Sergey Orlov
- 331
- 1
- 8
-
Will that work in google chrome? Because chrome thinks that another file in the same directory is cross domain. and if that's possible what would be the best way to do that? – KarelK Sep 01 '16 at 18:35
-
You need to use some server to serve the files. It is rather simple if you have python just go in the directory and type "python -m SimpleHTTPServer 8000" . Then you can go to http://localhost:8000/ and the server will serve you index.html or you can go to http://localhost:8000/some_file to get some file. Then in you main js file of in – Sergey Orlov Sep 01 '16 at 18:50
-
-
What are you building what is a use case? It will work If you want people to use app on your machine . If you want people from local network work with you app from theirs machines. It can be done by using local ip address. – Sergey Orlov Sep 01 '16 at 19:51
-
i have 2 files in the same folder (html.html and text.txt ) I want to read text.txt using javascript so I can post the data inside it to my php server without me having to do it manually. I'm accessing the files using the file protocol. – KarelK Sep 02 '16 at 04:43