Javascript IE+;XMLHttp+;CreateObjectURL错误
我尝试下载并在iFrame中显示远程文件的内容,并且在除IE之外的所有浏览器中都成功了(我尝试使用ie10)。 我使用了XMLHttpRequest、Blob、CreateOBjectUrl API来完成这个过程 在IE中,我无法查看iFrame中的文件内容,而且控制台上也没有显示任何特定的错误消息 我已经将我的代码粘贴到了这个线程的底部,下面是一步一步的解释Javascript IE+;XMLHttp+;CreateObjectURL错误,javascript,html,iframe,internet-explorer-10,Javascript,Html,Iframe,Internet Explorer 10,我尝试下载并在iFrame中显示远程文件的内容,并且在除IE之外的所有浏览器中都成功了(我尝试使用ie10)。 我使用了XMLHttpRequest、Blob、CreateOBjectUrl API来完成这个过程 在IE中,我无法查看iFrame中的文件内容,而且控制台上也没有显示任何特定的错误消息 我已经将我的代码粘贴到了这个线程的底部,下面是一步一步的解释 获取下载文档url和相应的mime 类型(在所有broswers中都非常好) 调用XMLHttp请求时 Http GET异步调用,响应类
// 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;
如果你能得到这方面的任何信息,请告诉我,这将非常有帮助。我知道在IE中不可能为你的blob条目获得正确的URL,我的任何尝试都没有成功。 我的替代方案, 1) 可以使用pdf.js,这是一个开源javascript库,它允许呈现pdf二进制文件和等效的pdf blob。 2) 利用开放的PDF库编写您自己的查看器,这将非常耗时,而且需要更多的学习努力 谢谢, 毗湿奴