1
我想下载并显示一个远程文件内的iFrame内容,并成功除了IE浏览器(我正在尝试与IE 10)的所有浏览器。 我已经使用XMLHttpRequest,Blob,CreateOBjectUrl API来完成该过程。IE + XMLHttp + CreateObjectURL错误
在IE中,我无法查看iFrame内的文件内容,也没有在控制台上显示特定的错误消息。
我贴了我的代码,这些线的底部,并一步步的解释如下
- 获取相应的MIME类型 (在所有broswers完美的罚款)下载文件网址&。
- 调用XMLHTTP请求,一个 的HTTP GET异步调用,如响应类型为“arraybuffer”(在所有浏览器完美 细)当完成下面3个步骤的XMLHttpGet是 执行。
- 使用适当的mimetype创建一个blob;(在所有其他浏览器中完美无瑕,通过使用MSSaveOrOpenBlob方法在IE中下载它,专门验证blob)。 4.InOrder将blob内容绑定到iFrame,使用“createObjectURL”(在所有浏览器中完美无缺,但在IE中我们没有获得完美的URL)创建blob url。
- 最后将URL与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;
请让我,如果你得到这方面的任何信息,将是非常有益的。