Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Javascript - Download multiple links in one click

The title might not be explicit enough, so let me explain my problem: I have a list of links displayed on my page, pointing to audio files. Clicking each one of those will prompt the browser to download the targeted file.

What I would like to have is a <button> at the bottom that would download every link of the list.

Here is my code:

const downloadAll = () => {
  const allLinks = document.querySelectorAll('a');

  for (i=0; i< allLinks.length; i++) {
    allLinks[i].click();
  }
}
<a href="https://link1">Download</a>
<a href="https://link2">Download</a>
<a href="https://link3">Download</a>

<button onclick="downloadAll()">download all</button>

When the user clicks on <button> only the last one is downloaded.

I have searched a lot and tried different options but I couldn't find a working one. I think the download part is the issue.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

try adding target="_blank" to your links like so

<a href="https://link1" target="_blank">Download</a>
<a href="https://link2" target="_blank">Download</a>
<a href="https://link3" target="_blank">Download</a>

this will tell browser to process every link in a separate tab. Tabs might be blocked by the browser though, so pay attention to top right corner(in chrome) there may be notification regarding blocked popups.

Here is the link to an article that shows some other ways using different libs. https://medium.com/twodigits/multi-file-download-using-javascript-9b0b8a14639b

about 4 years ago · Juan Pablo Isaza Relatório

0

Use download attribute to assign filename to each a tag that will trigger mulltiple download in browser

const downloadAll = () => {
  const allLinks = document.querySelectorAll('a');

  for (i=0; i<= allLinks.length; i++) {
    var each = allLinks[i]
    each.download = each.href
    each.click()
  }
}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda