使用javascript将文本文件保存在客户端计算机上 [英] Save text file on client machine using javascript
问题描述
我想在客户端计算机上创建文本文件,然后再写入该文件.并且在保存该文件时,我想问用户他想在哪里保存文件,即想通过保存"对话框询问....
I want to create text file on client machine and then want to write in that file. And while saving that file i want to ask user where he want to save file i.e. want to ask by save dialog box....
提前谢谢....
推荐答案
出于安全原因,JavaScript无法做到这一点.您无法在客户端计算机上创建文件,因为JavaScript在该环境中没有写权限.
That is not possible with JavaScript for security reasons. You cannot create files on the client machine, since JavaScript doesn't have write permission in that environment.
作为解决方法,您可以通过Ajax请求将要存储的文本发送到Web服务器,该Web服务器又可以生成文本文件供用户下载到所需的位置..不太平滑,但至少可以解决.
What you could do as a work around is to send the text that you want to store through an Ajax-request to the web server, which in turn can generate a the text-file for the user to download to a desired location. Not as smooth, but at least it is a work around.
这篇关于使用javascript将文本文件保存在客户端计算机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!