妙博客

世界上最可怜的人,结构没破位赚一点就跑,结构破位死扛幻想反转

js/html下载base64编码的图片

function downBase64(base64, fileName){
        function dataURLtoBlob(dataurl) {
            var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
                bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n);
            }
            return new Blob([u8arr], { type: mime });
        }
        function downloadFile(url,name){
            var a = document.createElement("a")
            a.setAttribute("href",url)
            a.setAttribute("download",name)
            a.setAttribute("target","_blank")
            let clickEvent = document.createEvent("MouseEvents");
            clickEvent.initEvent("click", true, true);
            a.dispatchEvent(clickEvent);
        }
        function downloadFileByBase64(base64,name){
            var myBlob = dataURLtoBlob(base64)
            var myUrl = URL.createObjectURL(myBlob)
            downloadFile(myUrl,name)
        }
        downloadFileByBase64(base64, fileName);
    }


«   2026年11月   »
一 二 三 四 五 六 日
1
2345678
9101112131415
16171819202122
23242526272829
30
网站分类
搜索
标签列表
文章归档
网站收藏
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合

Copyright Your 142132.com Rights Reserved. 赣ICP备17010829号-2