Blob createObjectURL download not working in Firefox (but works when debugging)

前端 未结 3 1019
野性不改
野性不改 2020-12-04 17:31

I have an odd problem, the function below is one I created based on what i found on the net about creating a Blob in the client on the fly with some binary data in (passed a

相关标签:
3条回答
  • 2020-12-04 17:59

    You're probably removing the resource too soon, try delaying it

        ...
        a.click();
        setTimeout(function(){
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);  
        }, 100);  
    }
    
    0 讨论(0)
  • 2020-12-04 18:03

    The above didn't solve the issue for me. But this one did instead:
    Programmatical click on <a>-tag not working in Firefox
    It was a problem with the triggering click event, not premature removal of the resource.

    0 讨论(0)
  • 2020-12-04 18:09

    this solution works for me in bot chrome and firefox for existing anchor element to download binary file

    window.URL = window.URL || window.webkitURL;
    
    var blob = new Blob([new Uint8Array(binStream)], {type: "octet/stream"});
    
    var link = document.getElementById("link");
    link.href = window.URL.createObjectURL(blob);
    
    0 讨论(0)
提交回复
热议问题