Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!