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

187
Views
file download in new tab in javascript

I am trying to download file by clicking on download button it should open the new tab and start downloading and once the download starts it closes the tab itself basically I do not want to have any effect on the original page. Here is my current code

const downloadHandler = (file) => {

    const a = document.createElement("a");
    a.href = file;
    a.setAttribute(`download`, file);
    a.click();
  };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I recommend using the download attribute for download instead of jQuery:

<a href="your_link" download> file_name </a>

This will download your file, without opening it.

about 4 years ago · Juan Pablo Isaza Report

0

<a href="https://yourlink.com" target="_blank" download>fileName</a>

This will open the HTML file in a new tab

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