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

82
Vistas
Looping through array of file urls opens only first URL Javascript

I've this short script to open URL's:

var x = document.querySelectorAll("a.Mylinks");
var myarray = [];
for (var i = 0; i < x.length; i++) {
  var link = x[i].href;
  myarray.push(link);
}
for (var i = 0; i < myarray.length; i++) {
  window.open(myarray[i], "_blank");
}

Array responds back with correct URLs, first URL opens and that is it, loop stops. Any ideas why this is happening and how this can be fixed? Any additional links or information would be helpful.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The problem you're facing is that browser you're using blocks an opening of too much tabs at the same time. Try disabling that blocking, usually you can find the needed button for that in the address bar.

about 4 years ago · Juan Pablo Isaza Denunciar

0

**Note Browser can block as opening of too much tabs at the same time.**

var x = document.querySelectorAll("a.Mylinks");
var myarray = [];
for (var i = 0; i < x.length; i++) {
  var link = x[i].href;
  window.open(x[i].href,Math.floor(Math.random() * 80000));
}
<a class='Mylinks' href='https://google.com'></a>
<a class='Mylinks' href='https://stackoverflow.com'></a>
<a class='Mylinks' href='https://nodejs.org'></a>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just change the target name from _blank to random series like "_blank" + i, then check it.

 for (var i = 0; i < myarray.length; i++) {
       window.open(link, '_blank' + i); 
 }
about 4 years ago · Juan Pablo Isaza Denunciar
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