Javascript:创建并保存文件 [英] Javascript: Create and save file

查看:163
本文介绍了Javascript:创建并保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数据要写入一个文件,并打开一个文件对话框,供用户选择保存文件的位置。如果它在所有浏览器中都可以运行,但它必须在Chrome中运行会很好。我想这样做所有的客户端。



基本上我想知道该功能中的内容:

  saveFile:function(data)
{
}

函数在数据中进行访问,用户选择一个位置来保存文件,并在该位置创建一个文件。



感谢提前。



编辑:
如果这有帮助,也可以使用HTML。

解决方案

github上的这个项目看起来很有希望:



https://github.com/eligrey/FileSaver.js


FileSaver.js实现W3C saveAs()

另请参阅这里的演示:

>

http://eligrey.com/demos/FileSaver.js/


I have data that I want to write to a file, and open a file dialog for the user to choose where to save the file. It would be great if it worked in all browsers, but it has to work in Chrome. I want to do this all client-side.

Basically I want to know what to put in this function:

saveFile: function(data)
{
}

Where the function takes in data, has the user select a location to save the file, and creates a file in that location with that data.

Thanks in advance.

EDIT: Using HTML is fine too, if that helps.

解决方案

This project on github looks promising:

https://github.com/eligrey/FileSaver.js

FileSaver.js implements the W3C saveAs() FileSaver interface in browsers that do not natively support it.

Also have a look at the demo here:

http://eligrey.com/demos/FileSaver.js/

这篇关于Javascript:创建并保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆