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

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

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 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