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

134
Views
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
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!