$('#dl').on('click', function(e){
let urlList = [url1, url2, url3, ... ];
fileDl(urlList, 0);
});
function fileDl(urlList, idx) {
let href = urlList[idx];
console.log(href);
loadFile(href, function (responce) {
if (responce!=null){
downloadAsFile(responce);
}else{
alert("DLに失敗しました");
}
if (idx >= urlList.length-1) {
$('#loading').remove();
} else {
fileDl(urlList, idx+1)
}
});
}
var loadFile = function(href, cb) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (this.readyState == 4 ){
if ( this.status == 200) {
cb(this.response);
}else{
cb(null);
}
}
}
xhr.open('GET', href, true);
xhr.responseType = 'blob';
xhr.send(null);
}
var downloadAsFile = function(blob) {
var objectURL = window.URL.createObjectURL(blob);
var link = document.createElement("a");
document.body.appendChild(link);
link.href = objectURL;
link.download = 'filename';
link.click();
document.body.removeChild(link);
};