Write to a file without external JS libraries (pure Javascript) in a browser ?

ε祈祈猫儿з 提交于 2020-01-06 02:05:29

问题


Is it possible to write a string to a file (create the file if it doesn't exist) without any external Javascript libraries , purely with Javascript code ?

I'm trying to implement a client side code that whenever it reaches a page (.ASPX) it writes few strings into a file (let's say output.txt) and that's it .

From everything I see over the internet , JavaScript is not allowed to write anything to the hard drive .

Is that so ? no workarounds ?


回答1:


As said in the comments, what you sound to try to achieve is intentionally very restricted for obvious security reasons of the visitor's machine.

Now "workarounds" could exist, depending on the actual objective you are trying to achieve (but which you did not mention).

  • Cookies to store simple data (like your strings) in the visitor's computer (so strictly speaking, it does the job you ask for, but you have no control on which text file is used).
  • Use a browser extension, which would have the permission to write on the visitor's filesystem. Applicable if you can get visitors to install such extension (e.g. if you are IT and can request employees installing specific software).
  • localStorage as proposed in IanKenney's comment, if you just want some persistent data.


来源:https://stackoverflow.com/questions/33707268/write-to-a-file-without-external-js-libraries-pure-javascript-in-a-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!