web页面提供blob数据下载

(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

你可能感兴趣的:(web页面提供blob数据下载)