I need to open the pdf file in IE Browser. Is there any way we can achieve that.This works only in 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);
CodePudding user response:
IE doesn't support URL.createObjectURL()
. IE has its own API for creating and downloading files, which is called msSaveBlob
or msSaveOrOpenBlob
. 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.
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:
if(window.navigator.msSaveOrOpenBlob) {
//IE11
window.navigator.msSaveOrOpenBlob(blobData, fileName);
}
else{
//Other browsers
window.URL.createObjectURL(blobData);
...
}