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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.