浏览器端批量下载
如果已知有链接url的情况:function fileDownload(filename, link) { const a = document.createElement("a"), //创建a标签 e = document.createEvent("MouseEvents");...
2024年10月29日
101字
如果已知有链接url的情况:
function fileDownload(filename, link) {
const a = document.createElement("a"), //创建a标签
e = document.createEvent("MouseEvents"); //创建鼠标事件对象
e.initEvent("click", false, false); //初始化事件对象
a.href = link; //设置下载地址
a.download = filename; //设置下载文件名
a.dispatchEvent(e); //给指定的元素,执行事件click事件
}downloadFileList.forEach((file, index) => {
setTimeout(function () {
fileDownload(file.fileName, file.ossUrl);
}, 300 * index);
});
文章评论区
欢迎留言交流