js下载
作者:
站着瞌睡 | 来源:发表于
2023-02-14 09:51 被阅读0次function downloadFile(url, fileName) {
fetch(url, {
method: "get",
mode: "no-cors",
referrerPolicy: "no-referrer",
})
.then((res) => res.blob())
.then((res) => {
const aElement = document.createElement("a");
aElement.setAttribute("download", fileName);
const href = URL.createObjectURL(res);
aElement.href = href;
aElement.setAttribute("target", "_blank");
aElement.click();
URL.revokeObjectURL(href);
});
}
本文标题:js下载
本文链接:https://www.haomeiwen.com/subject/hfkekdtx.html
网友评论