原生js base64格式数据 下载
/**
* 封装base64Str blob对象
* */
function base64toBlob (base64Str) {
var bstr = atob(base64Str), n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr]);
}
/**
* 下载文件 base64 数据,文件名(包括后缀)
* */
function download(base64Data,fileName){
var myBlob = base64toBlob(base64Data);
var myUrl = URL.createObjectURL(myBlob);
var link = document.createElement("a");
link.href = myUrl;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
标签:原生,base64Str,base64,js,link,var,document
From: https://www.cnblogs.com/qx-blog/p/18153327