If you also want to give a suggested name to the file (instead of the default 'download') you can use the following in Chrome, Firefox and some IE versions:

function downloadURI(uri, name) {
  var link = document.createElement("a");
  link.download = name;
  link.href = uri;
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
  delete link;
}

And the following example shows it's use:

downloadURI("data:text/html,HelloWorld!", "helloWorld.txt");
Answer from owencm on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › download-any-file-from-url-with-vanilla-javascript
Download Any File From URL with Vanilla JavaScript - GeeksforGeeks
Downloading files from a URL using vanilla JavaScript involves creating a link element, setting its href attribute to the file URL, and programmatically triggering a click event. This method allows users to download files without relying on ...
Published   August 5, 2025
Discussions

Can I download a file in JavaScript WITHOUT using blobs?
That’s why a manager is a manager and he should just stay in his lane. He clearly does not understand blob that well. More on reddit.com
🌐 r/webdev
30
103
March 4, 2024
How would you go about downloading a file from the web to the user's machine in Node.js?
With fetch. Here's a nice example answer from stack exchange: const downloadFile = (async (url, path) => { const res = await fetch(url); const fileStream = fs.createWriteStream(path); await new Promise((resolve, reject) => { res.body.pipe(fileStream); res.body.on("error", reject); fileStream.on("finish", resolve); }); }); Just call it with something like await downloadFile('https://github.com/path/to/thing', '/path/to/save/thing'); More on reddit.com
🌐 r/learnjavascript
8
2
March 24, 2022
How to download a file from remote url? <a download> previews the file but not download it
`` behaviour only works if the URL is the same origin. In this case it isn't, so you need to have a route handler do the fetching of the file, and then create a response with the downloaded file as the body while also setting the right header: https://stackoverflow.com/questions/20508788/do-i-need-content-type-application-octet-stream-for-file-download More on reddit.com
🌐 r/nextjs
2
2
February 16, 2024
Downloading a file from URL in TS/JS.
I want to create a function in TS which gets called on a button click, takes an image or PDF URL, uploaded in AWS, and then downloads it to the… More on reddit.com
🌐 r/learnprogramming
2
2
October 5, 2021
🌐
Kodeclik
kodeclik.com › javascript-download-file-from-url
How to download a file from a URL using Javascript
September 1, 2025 - We create a URL for the file data using the window.URL.createObjectURL() method and create a new element with the href attribute set to the URL of the file and the download attribute set to the desired filename.
🌐
CodingNepal
codingnepalweb.com › home › javascript projects › download any file from url with vanilla javascript
Download Any File From URL with Vanilla JavaScript
May 24, 2022 - If you liked this file downloader and want to get source codes or files, you can easily get them from the bottom of this page. But, before you download the files, let’s talk about the codes and concepts behind creating this file downloader with JavaScript. At first, I got the user entered file URL, and using fetch() API, I fetched the file.
🌐
GitHub
gist.github.com › gkhays › fa9d112a3f9ee61c6005136ebda2a6fd
Download a file from a URL using Node.js · GitHub
https : http; const request = client.get(url, function(response) { var len = parseInt(response.headers['content-length'], 10); var cur = 0; var total = len / 1048576; //1048576 - bytes in 1 Megabyte response.on('data', function(chunk) { cur += chunk.length; showProgress(file, cur, len, total); }); response.on('end', function() { console.log("Download complete"); }); response.pipe(localFile); }); } function showProgress(file, cur, len, total) { console.log("Downloading " + file + " - " + (100.0 * cur / len).toFixed(2) + "% (" + (cur / 1048576).toFixed(2) + " MB) of total size: " + total.toFixed
🌐
CodePel
codepel.com › home › vanilla javascript › javascript download file from url programmatically
JavaScript Download File From URL Programmatically — CodePel
February 16, 2025 - Here is a free JavaScript code snippet to download file from URL. You can view live demo and download the source code.
Address   Rafi Qamar Road, Al-Majeed Peradise Al Majeed Peradise, 62300, Bahawalpur
🌐
Transcoding
transcoding.org › home › javascript download file from url: a deep dive with code samples
JavaScript Download File from URL: A Deep Dive with Code Samples — Transcoding
February 3, 2024 - One such gem is FileSaver.js, which provides a simple way to save files on the client-side. ... import { saveAs } from 'file-saver'; const DownloadButton = ({ url, fileName }) => { const handleDownload = async () => { try { const response = await fetch(url); const blob = await response.blob(); saveAs(blob, fileName); } catch (e) { console.log('Whoops, something went wrong with the download:', e); } }; return ( <button onClick={handleDownload}>Download</button> ); }; // Usage // <DownloadButton url="https://example.com/file.pdf" fileName="cool-file.pdf" />
Find elsewhere
🌐
LogRocket
blog.logrocket.com › home › programmatically downloading files in the browser
Programmatically downloading files in the browser - LogRocket Blog
August 28, 2024 - Master file downloads in HTML using JavaScript, and explore the role of blobs, object URLs, and anchor elements.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript download
How to Download a File Using JavaScript | Delft Stack
February 2, 2024 - Set href as the URL created in the first step and download attribute as the downloaded file’s name. Attach this link to the document and simulate a click using the .click() method. Remove this link from the document. <!DOCTYPE html> <html> <head> <title>How to download files using JavaScript</title> </head> <body> <button onclick="download()"> Download Image </button> <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"> </script> <script> function download() { axios({ url: 'https://source.unsplash.com/random/500x500', method: 'GET', responseType: 'blob' }) .then((response) => { const url = window.URL .createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', 'image.jpg'); document.body.appendChild(link); link.click(); document.body.removeChild(link); }) } </script> </body> </html>
🌐
Atomizedobjects
atomizedobjects.com › blog › javascript › how-to-download-a-file-from-a-url-in-javascript
How to Download a File from a URL in JavaScript | Atomized Objects
In this article, we will explore different techniques and methods to download files from a URL using JavaScript. We will cover the use of anchor tags, the fetch() API, and the XMLHttpRequest object.
🌐
CoreUI
coreui.io › answers › how-to-download-a-file-in-javascript
How to download a file in JavaScript · CoreUI
December 2, 2025 - Learn how to programmatically download files in JavaScript using blob URLs and anchor elements for file download functionality.
🌐
Javascripts
javascripts.com › download-files-from-urls-with-javascript
How to Download Files from URLs with JavaScript
June 23, 2023 - We use JavaScript’s Fetch API to retrieve the file from the specified URL. Then, we convert the response into a blob object. Using the FileSaver.js library, we trigger the file download on the client side with the specified filename and extension.
🌐
DEV Community
dev.to › incoderweb › how-to-create-a-file-downloader-via-url-using-pure-javascript-obp
How to create a file downloader via url using pure javascript - DEV Community
May 26, 2022 - This tool (File Downloader via URL) can download any file like image, video, pdf, SVG, etc. Users have to paste a valid URL of the file and click the download button to download the file. Remember, the file should be publicly accessible to download.
🌐
Flexiple
flexiple.com › javascript › download-flle-using-javascript
How to Download a File Using JavaScript - Flexiple
JavaScript provides the ability to trigger file downloads from a web page using the `Blob` object and the `URL.createObjectURL` method to download a file using JavaScript, developers often employ specific techniques. JavaScript creates a `Blob` object, encapsulating the file data.
🌐
GitHub
gist.github.com › franciscojsc › 657371325f3d4791c5ecd9fe3d86c73b
Download a file using URL with Node.js · GitHub
Clone via HTTPS Clone using the web URL. ... Clone this repository at &lt;script src=&quot;https://gist.github.com/franciscojsc/657371325f3d4791c5ecd9fe3d86c73b.js&quot;&gt;&lt;/script&gt; Save franciscojsc/657371325f3d4791c5ecd9fe3d86c73b to your computer and use it in GitHub Desktop. ... This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
🌐
CodeSignal
codesignal.com › learn › courses › efficient-api-interactions-with-javascript › lessons › downloading-files-from-an-api-using-javascript
Downloading Files from an API Using JavaScript
GET requests are fundamental for retrieving files from an API. When you send a GET request using fetch, your client communicates with the server at a specified URL, asking it to provide the file. The server responds with the file data, if available and permissible, along with an HTTP status code (like 200 OK). Here's a basic example of downloading a file named welcome.txt from our API at http://localhost:8000/notes.
🌐
EaseUS
multimedia.easeus.com › video & audio downloader tips › how to download file from url online free 2026🆕
How to Download File from URL Online Free 2026🆕
3 weeks ago - FileGrab.net is a simple, user-friendly online tool that lets you download files directly from any URL—no software or sign-up required. Whether it's documents, images, videos, or audio files, just paste the file URL, hit "Download," and you're ...
🌐
npm
npmjs.com › package › js-file-downloader
js-file-downloader - npm
May 16, 2023 - import JsFileDownloader from 'js-file-downloader'; const fileUrl = 'http://...'; new JsFileDownloader({ url: fileUrl }) .then(function () { // Called when download ended }) .catch(function (error) { // Called when an error occurred });
      » npm install js-file-downloader
    
Published   May 16, 2023
Version   1.1.25
🌐
David Walsh
davidwalsh.name › javascript-download
Force Download with JavaScript
May 27, 2020 - function downloadFile(data, fileName, type="text/plain") { // Create an invisible A element const a = document.createElement("a"); a.style.display = "none"; document.body.appendChild(a); // Set the HREF to a Blob representation of the data to ...