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

411
Views
Need a delay within a for loop, Python, Flask, HTML, JavaScript

Hello and apologies if this has been asked and answered, but after couple hours each day for the past week searching, I have yet to find a good solution.

Issue: I have a Python/Flask served site where I have a specific button that will allow me to open up every instance of my customers sites, loaded from a database (custdata). The below code in it's original form works fine to open up all of the pages in new tabs. The issue I am having is to help reduce the initial load upon requesting the pages, I would like to have a half second delay between each iteration within the for loop.

Notes: As seen below, I have tried to use the setTimeout option with a delay of 500 milliseconds, but this seems to only delay the opening of the first iteration of the subsequent pages. The loop then opens the rest of the pages without any delay.

For example: If the database has 5 customers for a given server, the page will load, delay for 500ms, then load the 5 customer pages without any delay between them. The desired effect is to delay the opening of the customer pages between each customer page.

  
<head>
<script>
function myFunction() 
{
    {% for mydata in custdata %}
        window.setTimeout(function(){
                window.open("https://customer.mysite.com/launch/{{ custdata.customer_name }}", "_blank");
        }, 500);
    {% endfor %}
}
</script>
</head>

<body onload="myFunction()">
Customer pages should have loaded.  If so, you can close this page.  If not, ensure popups are not blocked for this site.
</body>

</html>```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks Paul M for the suggestion. below is the updated code to raise the timeout by 250ms per iteration within the for loop. This appears to have accomplished the end goal I was looking for:

<script>
function myFunction() 
{
    let delayiteration=0;
    {% for mydata in custdata %}
        window.setTimeout(function(){
                window.open("https://customer.mysite.com/launch/{{ custdata.customer_name }}", "_blank");
        }, delayiteration);
        delayiteration=delayiteration+250;
    {% endfor %}
}
</script>
</head>

<body onload="myFunction()">
Customer pages should have loaded.  If so, you can close this page.  If not, ensure popups are not blocked for this site.
</body>

</html>
about 4 years ago · Juan Pablo Isaza Report
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!