我正在尝试下载并在iFrame中显示远程文件的内容,并且除IE之外的所有浏览器都成功(我正在尝试使用IE 10)。 我已经使用XMLHttpRequest,Blob,CreateOBjectUrl API来完成这个过程。
在IE中,我无法查看iFrame中的文件内容,也没有在控制台上显示特定的错误消息。
我已将代码粘贴在此主题的底部,并按步骤解释如下
下面的代码段。
// Getting the document url and mime type ( Which is perfectly fine )
var downloadUrl=finalServerURL + "DocumentService.svc/GetItemBinary?id=" + itemId + "&version=" + version;
var mimeTypeForDownload = responseStore.mimeTypes[currentlySelectedObject.fileExtension];
window.URL = window.URL || window.webkitURL;
//Defining the XML Http Process
var xhr = new XMLHttpRequest();
xhr.open('GET', downloadUrl, true);
xhr.responseType = 'arraybuffer'; //Reading as array buffer .
xhr.onload = function (e) {
var mimeType = mimeTypeForDownload;
var blob = new Blob([xhr.response], { type: mimeType });
// Perfect blob, we are able to download it in both IE and non-IE browsers
//This below url from createObjectURL,
//Working perfectly fine in all non-IE browsers, but nothing happening in IE
var url = window.URL.createObjectURL(blob);
document.getElementById(documentContentiFrameId).setAttribute("src", url);
};
xhr.send;
如果你得到任何相关信息,请告诉我,这将非常有帮助。
答案 0 :(得分:1)
我开始知道在IE中无法为你的blob条目获取正确的URL,我的尝试都没有成功。 我的替代方案, 1)转到pdf.js,一个开源的javascript库,它允许渲染pdf二进制文件和等效的pdf blob。 2)利用开放的PDF库编写自己的观众,这将耗费大量时间,并且需要更多的学习努力。
谢谢, 毗