javascript;gutter:true;
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);
};</p>
<pre><code> downloadRes('文件url', '文件名');
</code></pre>
<p>
Original: https://www.cnblogs.com/huangcong/p/15908173.html
Author: 黄聪
Title: JS弹出下载对话框,实现跨域第三方文件另存为
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/551905/
转载文章受原作者版权保护。转载请注明原作者出处!