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

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

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