html 通过url 下载文件 |
您所在的位置:网站首页 › fetch跨域 › html 通过url 下载文件 |
不通过fetch 1、fetch(url)下载 可能会遇到跨域问题 fetch(url).then(res => res.blob().then(blob => { var a = document.createElement('a'); var url = window.URL.createObjectURL(blob); a.href = url; if(materialName){ a.download = materialName; }else{ a.download = filename; } a.click(); window.URL.revokeObjectURL(url); })) 2、直接a标签 let a = document.createElement('a'); a.setAttribute('href', downloadUrl); a.setAttribute('target', '"_blank"'); a.setAttribute('download', ''); a.click(); 3、window.location.href= url |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |