I’d like to track when a certain web-page is (or is not) in the foreground.
I’ve already experimented with the Page Visibility API, and I can use it to find out if my page is the currently active tab of its window. But I also need to know when my page’s window is not in the foreground (despite being the active one of that window).
Is this something I can detect using javascript?
I use
focusandblurevents for this, you can do it cross-browser on$(window)with JQuery. Your needs don’t appear to require the Page Visibility API, since you only care about if the tab (and window) has actual focus.