IE 11, blob下載解決方案


1. 解決toBlob(), 放在你的代碼toBlob即可

if (!HTMLCanvasElement.prototype.toBlob) {
        Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
            value: function value(callback, type, quality) {
                const canvas = this;
                setTimeout(() => {
                    const binStr = atob(canvas.toDataURL(type, quality).split(',')[1]);
                    const len = binStr.length;
                    const arr = new Uint8Array(len);
                    for (let i = 0; i < len; i++) {
                        arr[i] = binStr.charCodeAt(i);
                    }
                    callback(new Blob([arr], { type: type || 'image/png' }));
                });
            },
        });
    }

  

2. 下載:

  if (navigator.msSaveBlob) {
        // deal with IE 11, data是第一步toBlob的結果值
        window.navigator.msSaveOrOpenBlob(data, fileName);
    }
    else {
        const a = document.createElement('a');
        document.body.appendChild(a);
        a.download = fileName;
        a.href = window.URL.createObjectURL(data);
        a.click();
        a.remove();
    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM