0

I want to detect when the browser goes out of focus. More specifically, here is my case:

I have my page opened and when I change the tab, it can be detected using visibilitychange. But when I go to another app, ex: VS Code without specifically minimizing the browser window or changing the tab, it does not work.

Here is a representation:

  • A->my current tab where I want the change to be detected.
  • I go to tab B, the change is detected.
  • I come back to A and then without minimising the browser, I go to VS Code the change is not detected.
  • I go back to tab A, then to tab B and then go to VSCode, the change gets detected.
5
  • Your other app's window must not necessarily cover the browser window, they could both still be visible. If the API reported the page as invisible in that state, it would simply be wrong. (And I don't think it should be the job of an in-browser API, to check on whatever else might be going on on my desktop.)
    – CBroe
    Commented Mar 7 at 11:29
  • Possibly the same question, but it's unclear if things have moved on - the jquery solution seems to still work, but this question not tagged jquery and perhaps a bit of overkill to add it just for this: stackoverflow.com/questions/1060008/…
    – fdomn-m
    Commented Mar 7 at 11:31
  • @freedomn-m using angular for the project, so don't want to add jquery over it. Commented Mar 7 at 11:42
  • @CBroe the thing is I want to detect whether browser is now in focus, I guess chrome allows it through its own api, but that would mean I would have to detect it for specific browsers. I wanted to see if there is any single solution for it. Haven't been able to find any till now. Commented Mar 7 at 11:44
  • There are other solutions in that question
    – fdomn-m
    Commented Mar 7 at 11:55

0

Browse other questions tagged or ask your own question.