Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!