且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JavaScript写入文本文件?

更新时间:2023-01-23 10:50:53

JavaScript 不能从客户端读取/写入文件或直接向服务器写入文件。

JavaScript cannot read/write files from the client or write files to the server (directly).

如果要将文件写入服务器,请考虑使用将与javascript交互的服务器端脚本-和示例,了解如何使用少量PHP来做到这一点。

If you want to write files to the server consider using server-side scripts that will interact with your javascript - and example on how to do this with a little bit of PHP.

就客户端文件交互而言,出于安全原因,这是根本不可能的(除非将其上载到脚本中,以供读取)。

In terms of client file interaction this is simply impossible for security reasons (unless it is uploaded to the script in which case it is read accessible).

但是您可以在客户端上存储数据-我以前一直在使用 jStorage 并强烈推荐它。它可以跨浏览器运行(即使在IE 6上也是如此),并且非常易于使用。

You can however store data on clients - I have previously been using jStorage and highly recommend it. It works cross-browser (even on IE 6) and is extremely easy to use.