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

267
Visualizações
how to detect if window was refreshed or closed in js?

i know this question was asked before but i, can't get this to work.

I have a .aspx which contains a function on the onunload body tag. This will refresh the parent page.

At this point, i need to know if the page was refreshed/reloaded, because this logic will trigger the func call everytime and close my "child" page.

This is my code

<script type="text/javascript">
    function refreshparent(){
        window.opener.location.reload(true);
        window.close();
    }
</script>

This is whay i want to do

<script type="text/javascript">
    function refreshparent(){
      if(page.wasclosed){
        window.opener.location.reload(true);
        window.close();
      }else{
   //do nothing
      }
    }
    </script>

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can try something like this


window.onload = function () {
      if (!window.location.hash) {
        window.location = window.location + '#loaded';
        window.location.reload();
      }
    }

once the page refreshed the #loaded is added to the url and once #loaded us detected it stops refreshing meaning "true". then you can use search params anywhere to see if the page was reloaded. You can add this in a setTimeout function or something else.

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