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.