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
}
});
This works in all browsers (IE11, Firefox, Microsoft Edge, Chrome and Chrome Mobile) My documents are in multiple select elements. The browsers seem to have issues when you try to do it too fast... So I used a timeout.
This solution uses promises:
I fond that executing
click()
event ona
element inside afor 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 byclick()
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.
I execute download event
click()
every 300ms. When there is no more files to downloadurls.length == 0
then, I executeclearInterval
oninterval
function to stop downloads.plunker example: https://plnkr.co/edit/XynXRS7c742JPfCA3IpE?p=preview
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:
JS:
Having said this, I would still go with zipping the file, as this implementation requires JavaScript and can also sometimes be blocked as popups.
You can do it, creating mouse events and dispatching them to button. Sourse.
This was the method which worked best for me and didn't open up new tabs, but just downloaded the files/images I required: