jym*_*muk 13 javascript pdf blob angularjs internet-explorer-11
我试图使用本文中建议的方法显示二进制文件AngularJS:在角度应用程序中显示blob(.pdf).这在Chrome和FF中运行良好,但IE 11给了我"错误:访问被拒绝".有谁知道它是否与Blob对象有关并且可以指向正确的方向?这是我的js代码:
$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 () {
});
Run Code Online (Sandbox Code Playgroud)
和我的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>
Run Code Online (Sandbox Code Playgroud)
IE 11阻止显示blob,您需要使用以下内容:
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6889 次 |
| 最近记录: |