Posts

Post not yet marked as solved
1 Replies
Adding setTimeout would work fine only if you do not have forloop.If you have multiple documents to be downloaded and you are iterating over while loop, then this SetTimout would be applied for first iteration and all remaining iterations would be executed without any delay.We have to change this delay technique somehow.See how it should be as follows:Array.forEach((element, index) =>{var link = document.createElement("a"); link.download = filename; link.target = "_blank"; // Construct the URI link.href = DOWNLOAD_URL; document.body.appendChild(link); setTimeout(function() { link.click(); // Cleanup the DOM document.body.removeChild(link); DOWNLOAD_COMPLETED = true; document.getElementById('nextButton').onclick(); }, 500*index);});in this way we would add delay in each iteration of forloop.Would be helpfull if anyone is looking for multiple downloads on the single button