Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda