Html google chrome 中的 html5 saveAs 支持

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15211742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:08:08  来源:igfitidea点击:

html5 saveAs support in google chrome

htmlgoogle-chromehtml5-filesystem

提问by bsr

I am trying to use saveAsinterface as explained here

我正在尝试使用此处saveAs解释的界面

For the moment, I only worry about Google Chrome, and I uses latest Canary (Version 27.0.1429.0 canary)

目前,我只担心谷歌浏览器,我使用最新的 Canary(版本 27.0.1429.0 canary)

Qn1: the article says.

Qn1:文章说。

The W3C File API includes a FileSaver interface, which makes saving generated data as easy as saveAs(data, filename), though unfortunately it will eventually be removed from the spec.

W3C 文件 API 包括一个 FileSaver 接口,它使保存生成的数据像 saveAs(data, filename) 一样简单,但不幸的是,它最终将从规范中删除。

Why it would be removed?

为什么会被移除?

Qn2: Below code.

Qn2:下面的代码。

if (window.saveAs) {
    window.saveAs(blob, name);
}else{
    console.log("saveAs not supported")
}

prints

印刷

saveAs not supported 

So chrome doesn't support saveAs. That is not the impression I have reading many article online.

所以chrome不支持saveAs。这不是我在网上阅读许多文章的印象。

回答by Pierre

this is a polyfill, as explained in the article. You have to load the javascript file listed in the article, save it in your resources and link to it in your code: The repository is there: https://github.com/eligrey/FileSaver.js

这是一个 polyfill,如文章中所述。您必须加载文章中列出的 javascript 文件,将其保存在您的资源中并在您的代码中链接到它:存储库在那里:https: //github.com/eligrey/FileSaver.js

There are limitations in Chrome, though. If file already saved, the new saving name is incremented : myFile(1), then myFile(2), etc.

但是,Chrome 中存在一些限制。如果文件已经保存,新的保存名称会增加:myFile(1),然后是 myFile(2),等等。

I have now a bug on Chrome, which tells can it cannot OPEN the file, but it is just a false warning, as the file is well SAVED, which is the point.

我现在在 Chrome 上有一个错误,它告诉它不能打开文件,但这只是一个错误的警告,因为文件保存得很好,这就是重点。