JSFiddle - React, Tailwind, and code Playground
by Vladimir
HTML
<textarea></textarea><br />
<button onclick="do_dl();">Test downloading</button>
CSS
textarea {
width: 100%;
height: 500px;
}
JavaScript
function download_files(files) {
function download_next(i) {
if (i >= files.length) {
return;
}
var a = document.createElement('a');
a.href = files[i].download;
a.target = '_blank';
a.setAttribute('download', files[i].filename);
// Add a to the doc for click to work.
(document.body || document.documentElement).appendChild(a);
if (a.click) {
a.click(); // The click method is supported by most browsers.
}
// Delete the temporary link.
//a.parentNode.removeChild(a);
// Download the next file with a small timeout. The timeout is necessary
// for IE, which will otherwise only download the first file.
setTimeout(function() {
download_next(i + 1);
}, 100);
}
// Initiate the first download.
download_next(0);
}
function do_dl() {
var files = document.querySelector('textarea').value.split('\n');
for(var i=0; i < files.length; i++) {
files[i] = {
download: files[i],
filename:files[i].split('/').pop()
};
}
console.log(files);
download_files(files);
}