js prompt browser download dialog

Solutions on MaxInterview for js prompt browser download dialog by the best coders in the world

showing results for - "js prompt browser download dialog"
Fabiana
18 Nov 2017
1function downloadFile(file) {
2  // Create a link and set the URL using `createObjectURL`
3  const link = document.createElement("a");
4  link.style.display = "none";
5  link.href = URL.createObjectURL(file);
6  link.download = file.name;
7
8  // It needs to be added to the DOM so it can be clicked
9  document.body.appendChild(link);
10  link.click();
11
12  // To make this work on Firefox we need to wait
13  // a little while before removing it.
14  setTimeout(() => {
15    URL.revokeObjectURL(link.href);
16    link.parentNode.removeChild(link);
17  }, 0);
18}
similar questions
queries leading to this page
js prompt browser download dialog