Is it possible to download multiple files with a single click using jQuery?
So far, I have this code. Found it somewhere but it only downloads the last file.
.js
var links = [
'https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.exe',
'https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.dmg',
'https://s3.amazonaws.com/Minecraft.Download/launcher/Minecraft.jar'
];
function downloadAll(urls) {
var link = document.createElement('a');
link.setAttribute('download', null);
link.style.display = 'none';
document.body.appendChild(link);
for (var i = 0; i < urls.length; i++) {
link.setAttribute('href', urls[i]);
link.click();
}
document.body.removeChild(link);
}
.html
<button onclick="downloadAll(window.links)">Test me!</button>
I don’t think I can use plugins because this is for an html email. Or can I? I’m not really sure.
Are there other ways to achieve this if there’s no fix for the code above?
Any suggestion would be of great help. Thank you.
Regards,
Ellie