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

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