JS弹出下载对话框,实现跨域第三方文件另存为
作者:互联网
const downloadRes = async (url, name) => { let response = await fetch(url); let blob = await response.blob(); let objectUrl = window.URL.createObjectURL(blob); let a = document.createElement('a'); a.href = objectUrl; a.download = name; document.body.appendChild(a); a.click(); setTimeout(function () { document.body.removeChild(a); }, 1000); }; downloadRes('文件url', '文件名');
标签:body,跨域,另存为,url,objectUrl,对话框,let,blob,document 来源: https://www.cnblogs.com/huangcong/p/15908173.html