How can I let a user download multiple files when a button is clicked?

jquery multiple file download
angular download multiple files as zip
javascript download multiple images
how to download multiple files in single click in php
jquery download multiple files as zip
node js download multiple files
download excel file on button click jquery
coldfusion download multiple files

So I have a httpd server running which has links to a bunch of files. Lets say the user selects three files from a file list to download and they're located at:

mysite.com/file1 
mysite.com/file2
mysite.com/file3

When they click the download button I want them to download these three files from the links above.

My download button looks something like:

var downloadButton = new Ext.Button({
  text: "Download",
  handler: function(){
    //download the three files here
  }
});

The best way to do this is to have your files zipped and link to that:

The other solution can be found here: How to make a link open multiple pages when clicked

Which states the following:

HTML:

<a href="#" class="yourlink">Download</a>

JS:

$('a.yourlink').click(function(e) {
    e.preventDefault();
    window.open('mysite.com/file1');
    window.open('mysite.com/file2');
    window.open('mysite.com/file3');
});

Having said this, I would still go with zipping the file, as this implementation requires JavaScript and can also sometimes be blocked as popups.

Download multiple files with a single action, HTTP does not support more than one file download at once. There are two <​button onclick="downloadAll(window.links)">Test me!</button> forEach(url => { let iframe = document. Chrome will display a message to user to obtain his agreement to download multiple files the first time your site use it. Re: download multiple files with single button click Sep 06, 2012 02:49 PM | MattsDotNetUsername | LINK I don't think you can do this because the user must pick the location for each file.

This was the method which worked best for me and didn't open up new tabs, but just downloaded the files/images I required:

var filesForDownload = [];
filesForDownload( { path: "/path/file1.txt", name: "file1.txt" } );
filesForDownload( { path: "/path/file2.jpg", name: "file2.jpg" } );
filesForDownload( { path: "/path/file3.png", name: "file3.png" } );
filesForDownload( { path: "/path/file4.txt", name: "file4.txt" } );

$jq('input.downloadAll').click( function( e )
{
    e.preventDefault();

    var temporaryDownloadLink = document.createElement("a");
    temporaryDownloadLink.style.display = 'none';

    document.body.appendChild( temporaryDownloadLink );

    for( var n = 0; n < filesForDownload.length; n++ )
    {
        var download = filesForDownload[n];
        temporaryDownloadLink.setAttribute( 'href', download.path );
        temporaryDownloadLink.setAttribute( 'download', download.name );

        temporaryDownloadLink.click();
    }

    document.body.removeChild( temporaryDownloadLink );
} );

Downloading multiple files on a single button click (HTML Pages , Downloading multiple files on a single button click. Post by: Ishu Saxena , 1) User clicks on a link to download a batch of files. 2) The first download is initiated​  File.Copy can only copy from source to destination file. it cannot download . i want to open a Dialog to save file in user defined location. ZurdoDev 23-Jan-15 8:41am

I fond that executing click() event on a element inside a for loop for multiple files download works only for limited number of files (10 files in my case). The only reason that would explain this behavior that made sense to me, was speed/intervals of downloads executed by click() events.

I figure out that, if I slow down execution of click() event, then I will be able to downloads all files.

This is solution that worked for me.

var urls = [
  'http://example.com/file1',
  'http://example.com/file2',
  'http://example.com/file3'
]

var interval = setInterval(download, 300, urls);

function download(urls) {
  var url = urls.pop();

  var a = document.createElement("a");
  a.setAttribute('href', url);
  a.setAttribute('download', '');
  a.setAttribute('target', '_blank');
  a.click();

  if (urls.length == 0) {
    clearInterval(interval);
  }
}

I execute download event click() every 300ms. When there is no more files to download urls.length == 0 then, I execute clearInterval on interval function to stop downloads.

Download multiple files with a single action using jQuery, Is it possible to download multiple files with a single click using Found it somewhere but it only downloads the last file. .js var links <button onclick="​downloadAll(window.links)">Test me!</button>. I don't think I can use plugins because this is for an html email. New replies are no longer allowed. $("#fileRequest").click(function() { /* code to download? */ }); I'm definitely not looking for a way to create an anchor that looks like a button, use any back-end scripts, or mess with server headers or mime types. javascript html download. improve this question. edited Jul 23 '17 at 11:43. 103 silver badges. 147 bronze badges.

You can either:

  1. Zip the selected files and return the one zipped file.
  2. Open multiple pop-ups each prompting for a download.

Note - option one is objectively better.

Edit Found an option three: https://stackoverflow.com/a/9425731/1803682

Multiple files download on single link click, to download multiple file from a single user interaction: the click on the link. to use jQuery to simplify the concepts, you can use a simple script to accomplish this job. pointer is over the element, and the mouse button is pressed and released. Today I would let you know how to build your first application with ALPHA. I created a bit of a hybrid approach between Paul & Adam's approach: The link that opens the array of links is already in the html. The jquery just creates the array of links and opens each one when the "open-all" button is clicked:

I've solved this a different way by using window.location. It works in Chrome, which fortunately is the only browser I had to support. Might be useful to someone. I'd initally used Dan's answer, which also needed the timeout I've used here or it only downloaded one file.

var linkArray = [];
linkArray.push("http://example.com/downloadablefile1");
linkArray.push("http://example.com/downloadablefile2");
linkArray.push("http://example.com/downloadablefile3");    

function (linkArray) {
  for (var i = 0; i < linkArray.length; i++) { 
    setTimeout(function (path) { window.location = path; }, 200 + i * 200, linkArray[i]);
  }        
};

how to download multiple files with javascript one by one in a loop , how to download multiple files with javascript one by one in a loop I want to download images posted in chatter group by push a button in are not downloaded when I use the way of opening the download link of image like ['/​servlet/servlet.FileDownload?file=' + fileId] and put a interval in the loop. I am doing an application a Windows Form application. At first, a certain form appears, and after the user hits the next button, this form should be hidden and another form is shown. I tried to do it. I managed to hide the current form, but the next one won't show. Here is my attempt: This is the button's event handler

Using the HTML5 Download Attribute, One use of the download attribute is to set a different file download name than the actual link target itself. Downloading Multiple Files with One Click the above technique to invoke it on other elements, such as a button. At this point, you can use simple Windows file-management steps to copy or drag-and-drop the OneDrive files to a local folder on your computer. The Rant Microsoft developers continue to make the same mistake every time they update an interface — they ignore what users actually do .

Sequentially download multiple files (with jQuery), If a user wanted to download the files he could click the links one by one and then save them. But how to make the “Download selected files” button work. be a serious risk to allow javascript to write to a certain folder on disk. Switching to UseSubmitBehavior="false" injects a __doPostBack ('Button1', '') in the client-side onclick handler to work around that problem. Then, even if you disable the Button, the __doPostBack parameter lets ASP.NET know which control raised the PostBack and which events to fire on the server-side. Share a link to this answer.

download multiple files with single button click, on multiple file to be downloaded in single button click. my requirement them all and let the user download a zip with the custom set of files. I want user to click button, that will create new file from data on the page (export table rows into CSV) and download this file to user computer. After download I need refresh page (this will remove exported rows from table). – renathy Nov 6 '13 at 20:07

Comments
  • zip sucks if you're on, say, a phone. you can just trigger all three downloads, and chrome even recognizes this and prompts the use if they want to allow your site to "download multiple files". if you want to use zip, you can ajax in the files, zip them using jszip, and then download the zip file from the resulting JS tree object.
  • What is the best way to trigger the downloads? window.open("mysite.com/file1")?
  • i like using js methods (ex danml.com/js/download.js) when available, or <a download=file1.ext href=file1.ext>save</a>, which takes dataURLs. I don't typically download files though, more string generated by JS, so take my advice with a grain of salt
  • So I don't have access to the preventDefault() function is there anyway I can wait for a user to do an action on the first file before opening the second? What is happening is it goes straight to the third file and I can't download the first two.
  • What kind of action are you talking about? Because im not sure you can track that.
  • My call is window.open('mysite.com/file1', '_parent'); which overrides all the other windows (which doesn't work because I need to wait for a user interaction on each window). The reason why im using _self is because I don't want to switch windows, I want to stay on the parent window.
  • Then its best you create 2 pages: mysite.com/file1.html and mysite.com/file2.html. When each loads, you can start the file download for that page. And require the user interaction. Once the interaction has been verified then load the next page. (im not sure if i explained that correctly)
  • I've just been using this code @Dan and I've had problem in chrome where it ignores fast clicking, so had to set a timeout.
  • @IainMNorman interesting issue, a timeout seems a good enough solution, not sure how else it could be resolved
  • Just a FYI to others reading this: The download attribute won't work for cross-origin requests (at least with the latest version of Chrome). I think it used to but was patched out
  • I know that executing code on time intervals basis should be avoidable, but sometimes you gotta do what you gotta do.
  • This also works on Firefox, and reportedly also on Edge, but I have no interest in testing that myself (Edge is migrating to Blink themselves anyway - good riddance).