Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda