使用 HTML5 和 JavaScript 修改本地文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6457041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:49:50  来源:igfitidea点击:

Modifying Local Files Using HTML5 and JavaScript

javascripthtml

提问by Kirk Ouimet

Is there anyway I can use HTML5 and JavaScript to modify a file on my system? I'm OK with running Chrome or Firefox with specific options or opening permissions in some other way.

什么方法可以使用 HTML5 和 JavaScript 来修改我系统上的文件?我可以使用特定选项或以其他方式打开权限运行 Chrome 或 Firefox。

Ideally I would like test this by having my browser rename a file on my desktop.

理想情况下,我希望通过让浏览器重命名桌面上的文件来测试这一点。

回答by Jeremy Morgan

Yes, you can do this, this link details some of the available functionality:

是的,您可以这样做,此链接详细介绍了一些可用功能:

http://www.html5rocks.com/en/tutorials/file/filesystem/

http://www.html5rocks.com/en/tutorials/file/filesystem/

Just remember, it's not supported in the major browsers yet, and it's likely when it is many of your visitors will not upgrade for quite some time.

请记住,主要浏览器尚不支持它,并且很可能当您的许多访问者在很长一段时间内都不会升级时。

回答by Tak

No, as this would be a security vulnerability. As pointed out there are sandboxed file systems, or local database storage in HTML5, but not access to the whole file system.

不,因为这将是一个安全漏洞。正如所指出的,HTML5 中有沙盒文件系统或本地数据库存储,但不能访问整个文件系统。

You could achieve it with a certified Java applet, if you really wanted to achieve it through the browser. To be honest the browser is not the best place to be trying such things.

如果您真的想通过浏览器实现它,您可以使用经过认证的 Java 小程序来实现它。老实说,浏览器不是尝试此类事情的最佳场所。

回答by Knu

VBScriptshould be appropriate in your case. You will have to lower your internet zone security level though.
Once it's done just use ActiveXObject("Scripting.FileSystemObject")and its MoveFile method.

VBScript应该适合您的情况。不过,您将不得不降低 Internet 区域的安全级别。
完成后,只需使用ActiveXObject("Scripting.FileSystemObject")它的MoveFile 方法