简体   繁体   English

在IE浏览器中打开pdf

[英]open pdf in IE browser

I need to open the pdf file in IE Browser.我需要在 IE 浏览器中打开 pdf 文件。 Is there any way we can achieve that.This works only in chrome有什么方法可以实现吗?这仅适用于 chrome

var byteCharacters = atob(response.data);
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
  byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var file = new Blob([byteArray], { type: 'application/pdf;base64' });
var fileURL = URL.createObjectURL(file);
window.open(fileURL);

IE doesn't support URL.createObjectURL() . IE 不支持URL.createObjectURL() IE has its own API for creating and downloading files, which is called msSaveBlob or msSaveOrOpenBlob . IE 有自己的 API 用于创建和下载文件,称为msSaveBlobmsSaveOrOpenBlob The difference between the msSaveBlob and msSaveOrOpenBlob methods is that the former only provides a Save button to the user whereas the latter provides both a Save and an Open button. msSaveBlobmsSaveOrOpenBlob方法的区别在于前者只向用户提供一个保存按钮,而后者提供一个保存和一个打开按钮。

Besides, IE doesn't have PDF viewer embeded, so you can't display PDFs directly in IE 11. You can only use msSaveOrOpenBlob to handle blobs in IE, then choose to open or save the PDF file:另外,IE没有嵌入PDF查看器,所以无法在IE 11中直接显示PDF。IE中只能使用msSaveOrOpenBlob处理blob,然后选择打开或保存PDF文件:

if(window.navigator.msSaveOrOpenBlob) {
    //IE11
    window.navigator.msSaveOrOpenBlob(blobData, fileName); 
}
else{
   //Other browsers
    window.URL.createObjectURL(blobData);
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM