InvalidStateError in internet explorer 11 during blob creation

前端 未结 4 1035
灰色年华
灰色年华 2020-12-19 07:36

I\'m getting an InvalidStateError at the blob creation line on IE 11. Needless to say, it works in Chrome and Firefox. I can see that the binary data is my cli

相关标签:
4条回答
  • 2020-12-19 07:58

    Spent some time on this and actually found out adding new Uint8Array works:

    var blob = new Blob([new Uint8Array(request.response)], {type: 'application/pdf'});

    0 讨论(0)
  • 2020-12-19 08:02

    After instantiating an XmlHttpRequest with xhr.responseType = "blob" I was getting an InvalidStateError. However, moving xhr.responseType = "blob" to onloadstart solved it for me! :)

    xhr.onloadstart = function(ev) {
        xhr.responseType = "blob";
    }
    
    0 讨论(0)
  • 2020-12-19 08:08

    Is not a elegant way but it works on IE8 - IE11:

    var myForm = document.createElement("form");
    
    myForm.method = "POST";
    myForm.action = strURL;
    myForm.target = "_blank";
    
    var myInput = document.createElement("input");
    myInput.type = "text";
    myInput.name = "sim";
    myInput.value = JSON.stringify(/*data to post goes here*/);
    myForm.appendChild(myInput);
    
    document.body.appendChild(myForm);
    myForm.submit();
    $(myForm).hide();
    
    0 讨论(0)
  • 2020-12-19 08:18

    You need to use a BlobBuilder in that case.

    From: https://github.com/bpampuch/pdfmake/issues/294#issuecomment-104029716

    try {
       blob = new Blob([result], { type: 'application/pdf' });
    }
    catch (e) {
       // Old browser, need to use blob builder
       window.BlobBuilder = window.BlobBuilder ||
                            window.WebKitBlobBuilder ||
                            window.MozBlobBuilder ||
                            window.MSBlobBuilder;
       if (window.BlobBuilder) {
           var bb = new BlobBuilder();
           bb.append(result);
           blob = bb.getBlob("application/pdf");
       }
    }
    
    0 讨论(0)
提交回复
热议问题