How To Download Multiple Files From Javascript
I am trying to use window.location.href in a loop to download multiple files I have a table in which i can select file's, then i run a loop of selected and try navigate to the fil
Solution 1:
In some browsers (at least Google Chrome) support the follow:
$("<a download/>").attr("href", "https://code.jquery.com/jquery-3.1.0.min.js").get(0).click();
$("<a download/>").attr("href", "https://code.jquery.com/jquery-3.1.0.min.js").get(0).click();
$("<a download/>").attr("href", "https://code.jquery.com/jquery-3.1.0.min.js").get(0).click();
JSFiddle: https://jsfiddle.net/padk08zc/
Solution 2:
I would make use of iframes and a script to force the download of the files as Joe Enos and cmizzi have suggested.
The answer here will help with JavaScript for opening multiple iframes for each file: Download multiple files with a single action
The answers for popular languages will help with forcing downloads if the URL is actually something that can be served correctly over the web:
- PHP: How to force file download with PHP
- .Net: Force download of a file on web server - ASP .NET C#
- NodeJS: Download a file from NodeJS Server using Express
- Ruby: Force browser to download file instead of opening it
Ensure you change the links to point to your download script and also make sure you add the appropriate security checks. You wouldn't want to allow anyone to abuse your script.
Post a Comment for "How To Download Multiple Files From Javascript"