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

164
Visualizações
Detecting whether the web page is in focus in a mobile environment (android)

I need to monitor that the web page is always in the foreground and in focus. I have developed various controls, which work correctly on desktop. On mobile, however, they do not work, in particular if the browser window is displayed in Android multi-window mode, it is always in focus even when the user start another app of the smartphone.

What can I do?

These are some JavaScript codes I use to check that the site is in focus, on desktop browsers they work, on mobile browsers they are not completely reliable...

// check type 1
document.addEventListener( 'visibilitychange' , function() {
    if (document.hidden) {
        console.log("bye");
    } else {
        console.log("back");
    }
}, false );

// check type 2
$(document).mouseleave(function () {
    console.log("bye");
});
$(document).mouseenter(function () {
    console.log("back");
});

// check type 3
if (document.hasFocus()) {
    console.log("back");
}
else {
    console.log("bye");
}
about 4 years ago · Juan Pablo Isaza
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