html5 saveAs支持谷歌浏览器 [英] html5 saveAs support in google chrome

查看:2897
本文介绍了html5 saveAs支持谷歌浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照 saveAs 客户端rel =noreferrer>这里



目前,我只关心Google Chrome,并且使用最新的Canary (版本27.0.1429.0 canary)

Qn1:文章说。


W3C File API包含一个FileSaver接口,它可以节省
生成的数据和saveAs(数据,文件名)一样简单,但不幸的是
它最终会从规范中删除。


为什么会被删除?



Qn2:下面的代码。

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



打印

  saveAs不支持

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

解决方案

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



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

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


I am trying to use saveAs interface as explained here

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

Qn1: the article says.

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.

Why it would be removed?

Qn2: Below code.

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.

解决方案

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

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

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.

这篇关于html5 saveAs支持谷歌浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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