Table of contents
download a new file
const formV = document.querySelector("input");
const btn = document.querySelector("button");
btn.addEventListener("click", (e) => {
e.preventDefault();
filefetch(formV.value);
});
function filefetch(url) {
fetch(url)
.then((resp) => resp.blob())
.then((file) => {
let tURL = URL.createObjectURL(file);
let aTag = document.createElement("a");
aTag.href = tURL;
aTag.download = "file name";
document.body.appendChild(aTag);
aTag.click();
aTag.remove();
URL.revokeObjectURL(tURL);
});
}