Blob下载在IE中不起作用 [英] Blob download is not working in IE

查看:1596
本文介绍了Blob下载在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Angular.js控制器中有下载CSV文件:

I have this in my Angular.js controller that downloads a CSV file:

 var blob = new Blob([csvContent.join('')], { type: 'text/csv;charset=utf-8'});
 var link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
 link.href = URL.createObjectURL(blob);
 link.download = 'teams.csv';
 link.click();

这适用于Chrome,但不适用于IE。浏览器控制台日志说:

This works perfectly in Chrome but not in IE. A browser console log says:


HTML7007:通过关闭
的blob来撤销一个或多个blob URL 。这些URL将不再解析,因为支持URL的数据
已被释放。

HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed.

这是什么意思,怎么能我修理它?

What does it mean and how can I fix it?

推荐答案

尝试使用 useragent

if (navigator.appVersion.toString().indexOf('.NET') > 0)
        window.navigator.msSaveBlob(blob, filename);
else
{
 var blob = new Blob(['stringhere'], { type: 'text/csv;charset=utf-8' });
 var link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
 link.href = URL.createObjectURL(blob);
 link.download = 'teams.csv';
 link.click();
}

这篇关于Blob下载在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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