Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  31] [ 3]  / answers: 1 / hits: 26291  / 11 Years ago, mon, august 26, 2013, 12:00:00

I have the following javascript:



function downloadFiles(){
var files = [];
files.push('mysite.com/file1.txt');
files.push('mysite.com/file2.txt');
files.push('mysite.com/file3.txt');

for(var ii=0; ii<files.length; ii++){
window.location.href = files[ii];
}
}


The problem is this only downloads the last file in the list because the first two files get overwritten by the last one. How can I wait for the user's input on each file before moving on to the next file?


More From » download

 Answers
25

What I ended up doing:



function downloadFiles(){
var files = [];
files.push('file1.txt');
files.push('file2.txt');
files.push('file3.txt');

for(var ii=0; ii<files.length; ii++){
downloadURL(files[ii]);
}
}

var count=0;
var downloadURL = function downloadURL(url){
var hiddenIFrameID = 'hiddenDownloader' + count++;
var iframe = document.createElement('iframe');
iframe.id = hiddenIFrameID;
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.src = url;
}

[#76113] Sunday, August 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyemathewj

Total Points: 484
Total Questions: 107
Total Answers: 111

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;