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

95
Visualizações
Trying to download a file with javascript works in some browsers but not others

I have a problem I can’t solve. The following function inputs a file path and name and downloads the file. It works for chrome and edge browsers but with Vivaldi and pale moon browsers it will work once but not a second time. You need to reload the browser for it to work again. I have isolated the problem to this function alone. The alert works for all browsers, (first and second times) and shows the appropriate file path and name but no download takes place after the first successful attempt. There is no error in console. I thought that perhaps the browser didn’t like the creation of ‘var a’ a second time so included the ‘a.remove()’ but it makes no difference.

function StartDownload(filePath, fileName) {    // this is the function to download the book. Creates an html object 'a', adds the url to it, and then downloads it  
  //alert("got here: " + filePath + " fileName is: " + fileName);

  var a = document.createElement("a");
  a.href = fileUrl;
  a.setAttribute("download", fileName);
  a.click();

  //a.remove();
}

Could anyone suggest possible reasons why this code won’t download in those browsers after the first time?

about 4 years ago · Juan Pablo Isaza
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