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

76
Views
Close Tab after file download using Javascript/React JS

New tab gets opened if i want to download a file. In the below code i have closed the new tab after 10 sec. but the time should not be hardcoded. it should be the time taken for file download. Any suggestion how to calculate time taken for file download?

<a  href='' onClick={(e)=>activeTab(e,link) }>{filename} </a>

  const activeTab=(e,url)=> {
   const newWindow = window.open(url, '_blank');
   var startTime = (new Date().getTime());
   var endTime;
    if (newWindow) {
      //newWindow.opener =null
      if(newWindow.opener){
        setTimeout ( function () {
            newWindow.close ();
       }, 10000
      )
    }
    endTime = new Date().getTime()
  }
    e.preventDefault ();
    e.stopPropagation ();
  }

Please suggest me for any solutions.

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!