简体   繁体   English

从javascript将内容添加到.txt文件

[英]Add content to .txt file from javascript

Is their a way- client side, to add text to a file named text.txt in javascript? 他们是客户端将文本添加到JavaScript中名为text.txt的文件的方式吗?

In python: 在python中:

f = open("text.txt","w")
f.write("Hello World")
f.close()

would write "Hello World" into the text file. 将“ Hello World”写入文本文件。 I want to do something similar with javascript. 我想用javascript做类似的事情。

Note: I am running these files locally. 注意:我正在本地运行这些文件。

Its a bit more tricky than in python. 它比python更棘手。 The problem is that the browser sandboxes your session and your possibilities. 问题是浏览器将您的会话和可能性沙箱化。 It is possible to request storage space and read and write files in that space. 可以请求存储空间并在该空间中读写文件。

More info: http://www.html5rocks.com/en/tutorials/file/filesystem/ 更多信息: http : //www.html5rocks.com/en/tutorials/file/filesystem/

It would be a security nightmare if a javascipt file could just open files in the root or any other folder. 如果javascipt文件只能打开根目录或任何其他文件夹中的文件,那将是一个安全噩梦。 A different approach would be to upload the file in the client/ to the server edit it and send it back in a response. 另一种方法是将文件上传到客户端/服务器中,然后对其进行编辑并在响应中将其发送回去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM