web页面提供blob数据下载

ぃ、小莉子 提交于 2020-02-04 12:17:27
(function(w){
        w.downloadBlob = function download(blob,fileName){
            
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.style.display = 'none';
            a.href = url;
            a.download = fileName;
            document.body.appendChild(a);
            a.click();
        }
    })(window);
    const downloadButton = document.querySelector('a#download');
    downloadButton.onclick = function(){
        var blob = new Blob(['我是Blob'],{type: 'text/html'});
        downloadBlob(blob,'test.html');
    };

文件类型:

html:text/html
pdf:application/pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!