Search code examples
javascripthtmlclient-sideclient-side-scripting

Open a file for reading and writing in JavaScript


I would like a way of doing this:

  1. User selects client-side file from prompt.
  2. Browser passes file reference to client-side code.
  3. Code can read and write to the file indefinitely without any more user interaction.

It needs to run in the browser.

(This is not a duplicate of How do I open a file stream in javascript?; that question is over 5 years old and the file APIs have changed a lot since then. Also, it doesn't keep the file open.)


Solution

  • I dont think you can open a file w/o re-prompting the user unless your code is privileged in the browser (like a browser extension). I have found an api that let you do exactly what you want. but you need privileges to use it.