Local file access with JavaScript

前端 未结 13 2547
悲哀的现实
悲哀的现实 2020-11-21 04:07

Is there local file manipulation that\'s been done with JavaScript? I\'m looking for a solution that can be accomplished with no install footprint like requiring Adobe AIR.<

13条回答
  •  礼貌的吻别
    2020-11-21 04:52

    If the user selects a file via , you can read and process that file using the File API.

    Reading or writing arbitrary files is not allowed by design. It's a violation of the sandbox. From Wikipedia -> Javascript -> Security:

    JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files.

    2016 UPDATE: Accessing the filesystem directly is possible via the Filesystem API, which is only supported by Chrome and Opera and may end up not being implemented by other browsers (with the exception of Edge). For details see Kevin's answer.

提交回复
热议问题