嗨,有人知道如何在IE新标签页中打开Blob对象

var blob = base64toBlob(blobresponse);
    if (blob) {
        if (window.navigator &&
            window.navigator.msSaveOrOpenBlob) {
            var a = document.createElement("a");
            document.body.appendChild(a);
            a.href = window.URL.createObjectURL(blob);
            a.target = "_blank"
            a.download = "test.pdf";
            a.click();
        } else {
            var objectUrl = URL
                .createObjectURL(blob);
            window
                .open(objectUrl);
        }
    }

最佳答案

您可以使用iframe完成

var blob = base64toBlob(blobresponse);

if (blob) {
    var tab = window.open();
    var objectUrl = URL.createObjectURL(blob);
    if (window.navigator &&
        window.navigator.msSaveOrOpenBlob) { // for IE
        var iframe= document.createElement("iframe");
        tab.document.body.appendChild(iframe);
        iframe.src = objectUrl;
        iframe.setAttribute("style","width:100%;height:100%");
    } else { // for Chrome
        tab.location.href = objectUrl;
    }
}

关于javascript - IE如何在新标签页中打开Blob对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37937876/

10-12 06:38