ie11 Downloading Base64 documents

后端 未结 4 698
一向
一向 2020-12-11 02:19

I have tried pretty much everything at this point and I cannot get anything to work in ie.

I need ie to download base64 documents from an attachment panel. I have n

4条回答
  •  隐瞒了意图╮
    2020-12-11 02:41

    IE, in classic fashion, requires you to use a proprietary method for "saving" a blob.

    msSaveBlob or msSaveOrOpenBlob is what you're looking for.

    Instead of adding it as the href, add an onclick handler to your a tag and call navigator.msSaveBlob(blob, "Sample Name");

    Additionally if you need to support other browsers you'll need some other code to support those browsers.

    For example:

    var content = new Blob(["Hello world!"], { type: 'text/plain' });
    var btn = document.getElementById('btn');
    
    if (navigator.msSaveBlob) {
      btn.onclick = download;
    } else {
      btn.href = URL.createObjectURL(content);
      btn.download = true;
    }
    
    function download() {
      if (navigator.msSaveBlob) {
        navigator.msSaveBlob(content, "sample.txt");
      }
    }
    Download the text!

提交回复
热议问题