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

查看:56
本文介绍了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 URL 通过关闭 blob 被撤销它们是被创建的.这些 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?

推荐答案

试试这个,thisuseragent

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天全站免登陆