Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  36] [ 5]  / answers: 1 / hits: 18247  / 15 Years ago, mon, december 14, 2009, 12:00:00

Based on the other answers on this site, I already feel like I know the answer to this question, but, as it's slightly different, I wanted to ask.



Is it possible to access local files from JavaScript that is running locally on the machine (AKA, my website address will be file:///C:/...)? Or, is this sandboxed as well?



What I am trying to do: I have a standalone computer that I want people to be able to drop in JSON or XML files into a local folder which are read in at the creation of the site and used to generate a single web page. If the JavaScript solution is not possible, can you provide any other suggestions?



Thank you.


More From » javascript

 Answers
61

A webpage can read any file on the same server as it was loaded from (this is the cross-site policy of JavaScript). That means that the page file:///C:/mywebsite/index.html can read the file file://C:/somedir/somefile.xml. To read this file, either use ajax, load it in an iFrame or load it as a javascript or css file.



Several browsers support custom methods for loading local file (and other interesting things), IE has activeX and Firefox has XPCOM.


[#98072] Thursday, December 10, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lailab

Total Points: 706
Total Questions: 102
Total Answers: 95

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;