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

159
Views
document.click in for-loop only work once?

I'm trying to download some object in the page from console. But it only save when I=3(last iteration), I think the problem may be the need to wait for downloads, but idk how to solve it.

First, the elements are render by canvas, so I turn them to image format. Then, turn them into element, and click it to download.

I use the way in How to save a base64 image to user's disk using JavaScript?

But it only work in last iteration... any help? much thanks.

for(let i=1;i<=3;i++){
    // load image
    item_id = 'page'+i;
    document.getElementById(item_id)
    let image = document.getElementById(item_id).toDataURL("image/png").replace("image/png", "image/octet-stream");

    // download image
    var link = document.createElement("a");
    document.body.appendChild(link);
    link.setAttribute("href", image);
    link.setAttribute("download", item_id+'.png');
    link.click();
}
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!