【问题标题】:AngularJS "Blob" not working in IE8, IE9 and FirefoxAngularJS“Blob”在 IE8、IE9 和 Firefox 中不起作用
【发布时间】:2017-08-30 10:59:08
【问题描述】:

请有人帮我解决我在 angularJs 中使用“Blob”下载 excel 文件的问题。它在 Chrome 和 IE10 和 11 中工作,但是当我使用 Firefox 和 IE8&9 时,没有弹出下载会告诉在哪里保存或打开它,就像在 Chrome 中一样。

我的 API 数据成功返回要下载的字节,但我的客户端脚本无法下载。

这是我在 AngularJS 中的代码:

    $scope.LoadData = function () {
        $scope.yearIsLoading = true;
        reportsService.getAssessmentReports($scope.filter).$promise.then(function (response) {
            if (response != null) {
                var file = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
                saveAs(file, 'Assessments Report');
                $scope.yearIsLoading = false;
            }
        });
    };

这是我在 IE8 和 IE9 中得到的错误:

[IE8 and IE9 Error][1]

在 Firefox 中我看不到错误,但单击导出按钮后没有任何反应。

提前感谢可以帮助我解决此问题的人。 :)

【问题讨论】:

  • 对不起,我认为图像的链接已损坏,但这里是 IE8 和 IE9 中的错误链接。谢谢 :) i.stack.imgur.com/Fi2vt.png
  • 请检查它在 IE 8 中是否兼容:developer.mozilla.org/en-US/docs/Web/API/Blob
  • 正如 kat 指出的,Blob 在您的目标浏览器中不受支持。
  • 哦,我明白了。但是对于如何使用上述浏览器在 angularJs 中下载我的字节数据有什么建议吗?再次感谢您的帮助。

标签: c# asp.net angularjs blob


【解决方案1】:

你可以试试这样的:

var file = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });

if(window.navigator.userAgent.indexOf("MSIE ") > 0 || window.navigator.userAgent.indexOf("Trident/ ") > 0 || window.navigator.userAgent.indexOf("Edge/") > 0)
{
   window.navigator.msSaveOrOpenBlob(file);
}

【讨论】:

  • 嗨@eminlala 感谢您的帮助,但仍然出现错误。现在我试着做我在谷歌中找到的东西,我在我的项目中添加了假的 Blob.js,它现在已经知道使用 IE8 的“blob”,但仍然无法下载文件。我收到一个错误“对象不支持属性或方法'msSaveOrOpenBlob”
  • 它适用于我的下载 pdf 功能。对此感到抱歉:(。
猜你喜欢
  • 2013-10-23
  • 2016-01-29
  • 1970-01-01
  • 2013-03-16
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2014-09-29
相关资源
最近更新 更多