是否有允许将字符串保存为txt文件并跨浏览器工作的JavaScript库?
过去,我一直在使用Downloadify,但出于以下几个原因,我正在考虑另一种选择:
发布于 2011-06-24 09:15:37
据我所知,唯一的方法是使用data: URL强制下载:
var data = "This is a test";
window.location.href = "data:application/x-download;charset=utf-8," + encodeURIComponent(data);这里有两个渔获物:
奖励阅读:2010年2月,W3.org讨论了修复第二个问题:http://lists.w3.org/Archives/Public/uri/2010Feb/thread.html#msg58。然而,到目前为止,这似乎还没有进入任何规范,更不用说浏览器实现了。
发布于 2012-02-27 11:24:51
这是你需要什么。但还不是跨浏览器的。在谷歌Chrome上工作。
<a download="MyFile.txt"
href="your-data-uri-here"
draggable="true"
class="dragout"
>Download ready</a>而且维基百科有一个很好的关于数据URI的文章
发布于 2022-08-07 14:26:03
FileSaver API兼容跨浏览器。
var text = "Hello, world!";
var blob = new Blob([text], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "filename.txt");https://stackoverflow.com/questions/6464828
复制相似问题