Download multiple files with a single action using jQuery

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

Try creating invisible iframes and then using jquery/javascript to change the frames URLs.

I would strongly advise against trying to trigger downloads through email. Point the email link to a webpage, even if that webpage is just a blank javascript one. (Though every SEO person in the thread will be screaming ‘no make it redirect to the homepage after starting the downloads!’)

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.