How to Download File in Javascript

In this article, you will learn how to download a file in Javascript. Let’s say you want to download Codesource.io’s logo. Download File In order…

The post How to Download File in Javascript appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to download a file in Javascript.

Let’s say you want to download Codesource.io’s logo.

Download File

In order to download a file, you can use the HTML’s download attribute.

function download(fileUrl, fileName) {
  var a = document.createElement("a");
  a.href = fileUrl;
  a.setAttribute("download", fileName);
  a.click();
}

download("https://codesource.io/wp-content/uploads/2020/08/codesource.png", "Codesource_Logo.png");

Note: The HTML’s download attribute functions by downloading the supplied file URL upon clicking.

The post How to Download File in Javascript appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-03-06T13:35:29+00:00) How to Download File in Javascript. Retrieved from https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/

MLA
" » How to Download File in Javascript." Ariessa Norramli | Sciencx - Saturday March 6, 2021, https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/
HARVARD
Ariessa Norramli | Sciencx Saturday March 6, 2021 » How to Download File in Javascript., viewed ,<https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Download File in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/
CHICAGO
" » How to Download File in Javascript." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/
IEEE
" » How to Download File in Javascript." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/. [Accessed: ]
rf:citation
» How to Download File in Javascript | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/03/06/how-to-download-file-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.