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

628
Visualizações
Javascript function not running on my Flask App
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div id="load" class="load">
      <h3 >{{load}}</h3>
      <img  src="{{ load }}" id="image" style="height:500px;width:500px;"  />
    </div>
      <script type="text/javascript">
        document.getElementById("image").addEventListener("loadstart", refresh);

        function refresh() {
          window.location.reload();
        }
      </script>
  </body>
</html>

Flask server is running on http://0.0.0.0:5000/, after every HTTP POST new image is loaded to src="{{ load }}". I'd like website to refresh by itself using function refresh, but it is not working. Does anyone has idea why?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The image is already loaded when your script runs

Also images do not have a loadStart

Use the window load instead

and give the user a chance to enjoy the image

window.addEventListener("load", function() {
  setTimeout(function() {
    window.location.reload(1);
  },3000)
})
<div id="load" class="load">
  <h3>{{load}}</h3>
  <img src="{{ load }}" id="image" style="height:500px;width:500px;" />
</div>

You can also just load the image

window.addEventListener("load", function() {
  setTimeout(function() {
    document.getElementById('image').src = '{{ load }}'; // you may want to add something random to not cache
  },3000)
})
<div id="load" class="load">
  <h3>{{load}}</h3>
  <img src="{{ load }}" id="image" style="height:500px;width:500px;" />
</div>
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