在 IE 11 中显示二进制文件 (pdf) [英] Displaying binary file (pdf) in IE 11

查看:31
本文介绍了在 IE 11 中显示二进制文件 (pdf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用这篇文章中建议的方法显示一个二进制文件 AngularJS:在 Angular 应用程序中显示 blob (.pdf).这在 Chrome 和 FF 中运行良好,但 IE 11 给我错误:拒绝访问".有谁知道它是否与 Blob 对象有关并且可以指出我正确的方向?这是我的js代码:

$http.get(baseUrl + apiUrl, { responseType: 'arraybuffer' }).成功(功能(响应){var file = new Blob([response], { type: 'application/pdf' });var fileURL = URL.createObjectURL(file);$scope.pdfContent = $sce.trustAsResourceUrl(fileURL);}).错误(函数(){});

和我的 html:

<div ng-controller="PDFController" class="modal Fade" id="pdfModal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog modal-lg"><div class="modal-content" onloadstart=""><object data="{{pdfContent}}" type="application/pdf" style="width:100%; height:1000px"/>

解决方案

IE 11 阻止显示 blob,需要使用以下内容:

 var byteArray = new Uint8Array(someByteArray);var blob = new Blob([byteArray], { type: 'application/pdf' });如果(window.navigator && window.navigator.msSaveOrOpenBlob){window.navigator.msSaveOrOpenBlob(blob);}别的 {var objectUrl = URL.createObjectURL(blob);window.open(objectUrl);}

I am trying to display a binary file using the method suggested in this post AngularJS: Display blob (.pdf) in an angular app. This is working nicely in Chrome and FF, but IE 11 is giving me "Error: Access Denied". Does anyone know if it has something to do with the Blob object and can point me in the right direction? Here is my js code:

$http.get(baseUrl + apiUrl, { responseType: 'arraybuffer' })
          .success(function (response) {                  
             var file = new Blob([response], { type: 'application/pdf' });
             var fileURL = URL.createObjectURL(file);
             $scope.pdfContent = $sce.trustAsResourceUrl(fileURL);
           })
           .error(function () {                        
           });

and my html:

<div ng-controller="PDFController" class="modal fade" id="pdfModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
    <div class="modal-content" onloadstart="">
        <object data="{{pdfContent}}"  type="application/pdf" style="width:100%; height:1000px" />
    </div>
</div>

解决方案

IE 11 blocks display of blob, you need to use the following:

                    var byteArray = new Uint8Array(someByteArray);
                var blob = new Blob([byteArray], { type: 'application/pdf' });
                if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                    window.navigator.msSaveOrOpenBlob(blob);
                }
                else {
                    var objectUrl = URL.createObjectURL(blob);
                    window.open(objectUrl);
                }

这篇关于在 IE 11 中显示二进制文件 (pdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆