Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda