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

135
Visualizações
SetTimeout inside for loop Javascript

I want to create a pop window and open a list of URLs in the browser. So when the first page loads in the pop up window, Wait for the page to load then open the next page... Go through the list of urls. To wait for the page to load, I use setTimeout. But I can't seem to make my code work, because of the for loop and the setTimeout. The window skips directlt to the last url in the list. Is there any other way I can make it work? Thank you,

Here's my code:

// exammple of list urls
var my_list = ['https://www.youtube.com/watch?v=77kOn5NZBHw',
  'https://www.youtube.com/watch?v=1IRo21UhvZg',
  'https://www.youtube.com/watch?v=yRJxz0NicgI'
]

// open a new pop up window
var response = window.open(my_list[0], 'new', true);

for (let i = 0; i < my_list.length; i++) {
    setTimeout(function() {
    console.log(response.location.href);
    response.location = my_list[i];
  }, 3000)

};
about 4 years ago · Santiago Trujillo
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