我想呈現一個PDF內部iframe。它在Mozilla(v54)和Chrome(v59)上運行良好,但是當我單擊加載PDF的鏈接時,IE(v11)中沒有任何反應。經過多次調試,我發現Chrome/Firefox中的URL是blob:http://localhost:37444/5a8e7fed-cd61-4c58-904c-fad2ae169718,而在IE(v11)中它是blob:B7395CB5-169D-471F-BB8F-AA90EAFB6DDB。爲什麼URL.createObjectURL(BLOB)不附加在IE(V11)的HTTP請求URL.createObjectURL(斑點)不在IE中創建正確的URL 11
function (iframe, url, headers) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = handler;
xhr.responseType = "arraybuffer";
headers.forEach(function (header) {
xhr.setRequestHeader(header[0], header[1]);
});
xhr.send();
function handler() {
if (this.readyState === this.DONE) {
if (this.status === 200) {
var blob = new Blob([xhr.response], { type: "application/pdf" });
var objectUrl = URL.createObjectURL(blob);
iframe.src = objectUrl;
} else {
console.error('XHR failed', this);
}
}
}
[在IE 11中顯示二進制文件(pdf)]的可能副本(https://stackoverflow.com/questions/26161314/displaying-binary-file-pdf-in-ie-11) – demo
您建議的解決方案說你必須在IE(v11)中打開或保存,但我想在模態框中呈現PDF。如果有的話,請提出解決方法 –