How to implement this functionality?
When the user presses the Download link he will receive a download confirmation message and where he wants to save the file.
This download takes an average of 30s (you can get up to more depending on the date required).
I wanted to disable this link during the time the download is done and return to normal when the download is complete.
Is there an event to capture the beginning and the end of the download?
Update
My question needed two answers to be complete. @LeAndrade replied to a part of it (like disabling the <a>
link.
I'll post here as I did to capture the end of the download.
setcookie("statusDownloading", "done", time() + (300), "/");
On the front end when the user clicks on the link, the link is disabled (or removed) and starts a loop that looks for the cookie sent by php, in this case statusDownloading
. When the cookie is found, the link is reestablished, the cookie is deleted, and the loop is stopped.
function removeLink () {
let htmlObj=$('#LinkDownload');
htmlObj.detach();
setTimeout(function(){
let condition=true;
while (condition) {
let theCookies = document.cookie.split(';');
for (let i = 1 ; i <= theCookies.length; i++) {
let str = theCookies[i-1];
let cookie=str.split("=");
let cookieName = cookie[0];
if(cookieName.trim() == 'statusDownloading'){
htmlObj.appendTo('#parentOfLinkDownload');
document.cookie = 'statusDownloading=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
condition=false;
break;
}
}
}
}, 1000);
}