跨浏览器另存为.txt
是否有一个 JavaScript 库允许将字符串保存为 txt 文件,并且可以跨浏览器工作?
过去,我一直在使用 Downloadify,但出于以下几个原因我正在考虑另一个选择:
- 我希望找到一个纯 JavaScript 解决方案,不需要 Flash
- 似乎 Downloadify 不再更新 (过去 18 个月没有更新)
- 我在 IE 9 中遇到 Downloadify 问题,字符串被切断
Is there a JavaScript library that allows to save strings as txt files, and works cross-browser?
In the past, I have been using Downloadify, but I am looking at another option for a couple reasons:
- I hope to find a pure JavaScript solution, without the need for Flash
- it seems that Downloadify is not updated anymore
(no update in the past 18 months) - I am experiencing an issue with Downloadify in IE 9, where strings are cut off
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是您需要的。但它还不是跨浏览器的。适用于 Google Chrome。
维基百科还有一篇很好的关于数据 URI 的文章
Here is what you need. But it's not cross-browser yet. Works in Google Chrome.
Also Wikipedia has a good article about Data URI
据我所知,唯一的方法是使用 data: URL 强制下载:
这里有两个问题:
额外阅读:2010 年 2 月,W3.org 进行了一次有关解决第二个问题的讨论:http://lists.w3.org/Archives/Public/uri/2010Feb/thread.html#msg58。然而,到目前为止,这似乎还没有纳入任何规范,更不用说浏览器实现了。
As far as I know, the only way is to use data: URLs to force a download:
Two catches here:
Bonus reading: there was a W3.org discussion in February 2010 on fixing the second problem: http://lists.w3.org/Archives/Public/uri/2010Feb/thread.html#msg58. However, this doesn't seem to have made it into any specification so far, let alone browser implementations.
FileSaver API 跨浏览器兼容
FileSaver API is cross-browser compatible