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

98
Vistas
Does execution of the setTimeout function ensures that user was on the page for the given time?

As the question states:

setTimeout(myFunc, delay);

myFunc(){
  //do something
}

So can I consider that if myFunc() is called after the delay time, that ensures that the user was on the page for delay amount of time?
Basically, I wanted to execute a function after making sure that the user was on the page for a given amount of time? So is this the correct way of doing it with javascript or is there an even better option to do it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Page_Visibility_API allows you to check if user is on page: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API AND it also has method visibilitychange which is the preferable way probably.

Example: Pausing music on transitioning to hidden

document.addEventListener("visibilitychange", function() {
  if (document.visibilityState === 'visible') {
    backgroundMusic.play();
  } else {
    backgroundMusic.pause();
  }
});
about 4 years ago · Juan Pablo Isaza 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