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

267
Views
How do I download a file in javascript without disconnecting web-sockets or flashing a new tab?

After a long running server job, I need to automatically trigger a file download in my user's browser. I also have active websocket connections that I need to maintain in case the user is preforming different tasks in my web app. Originally I was doing this:

window.location.replace(downloadLink);

However, after that line executed I would miss websocket messages. This question deals with the same problem: On-Click A-tag with Href, socket gets disconnected

Then I tried this:

window.open(downloadLink, "_blank");

However this flashes a new tab open and closes it immediately. Its very jarring if the user was working on something else. I have also tried this:

axios.get(downloadLink, { responseType: "blob" }).then((response) => {
  const fileURL = window.URL.createObjectURL(new Blob([response.data]));
  const docUrl = document.createElement("a");
  docUrl.href = fileURL;
  docUrl.setAttribute("download", fileName);
  document.body.appendChild(docUrl);
  docUrl.click();
});

This works but it downloads the file in the background. This file is very large so I would like the user to be able to see download progress in the downloads bar at the bottom of the page.

Does anyone know how to download a file without disconnecting web-sockets or opening a new tab while still displaying the browsers file download progress?

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!