0

Backstory:
I am creating a development tool for web development. This tool loads a users webpage into an iframe, this allows the program to resize the iframe and simulate mobile screen sizes. I also want to build in a tool that automatically refreshes the iframe when local content is changed. To do this I am going to use Ajax to load files in and every 5 seconds or so compare the file to its previous version from 5 seconds ago. I currently have it working with just one file.

Question:
Is there a way to get all the files in a directory with Ajax. The little javascript same origin rule does not apply because the user is running this tool locally from the same directory as the project, no files from a server are being pulled.

Noah Huppert
  • 4,028
  • 6
  • 36
  • 58

1 Answers1

1

Javascript which runs on the client machine can't access the local disk file system due to security restrictions.

If you want to access the client's disk file system then look into an embedded client application which you serve up from your webpage, like an Applet, Silverlight or something like that. If you like to access the server's disk file system, then look for the solution in the server side corner using a server side programming language like Java, PHP, etc, whatever your webserver is currently using/supporting.

hanleyhansen
  • 6,304
  • 8
  • 37
  • 73
  • I am currently able to load files in the working directory of the user. I believe you are thinking like this is a server app(Might not have made it clear that its not). This is an app that users drag into there working directory and then double click on an html file(Or user a local dev server) – Noah Huppert Dec 31 '13 at 22:25
  • @NoahHuppert The same applies. You can't access the filesystem using JavaScript. Be it in the current directory or not. It's a violation of the sandbox. JavaScript in the browser is sandboxed. – hanleyhansen Dec 31 '13 at 22:27
  • @NoahHuppert the url parameter makes a browser request. That does not mean that JavaScript has access to the filesystem. You had to explicitly define the file that you want the browser to request on your behalf. You can't just list the contents of a directory in JavaScript. I would recommend an HTML input of type "file" which allows the user select the files themselves. – hanleyhansen Dec 31 '13 at 22:41
  • @NoahHuppert no problem see [this](http://stackoverflow.com/questions/15537424/get-a-list-of-all-folders-in-directory) post for even more details. – hanleyhansen Dec 31 '13 at 22:46