According to http://www.w3.org/TR/page-visibility/,
On getting, the hidden attribute MUST return true if the Document contained by the top level browsing context (root window in the browser's viewport) [HTML5] is not visible at all. The attribute MUST return false if the Document contained by the top level browsing context is at least partially visible on at least one screen.
However, using the following script:
setInterval(function() {console.log(document.hidden);}, 1000)
it keeps printing false when the browser is running in the background, i.e. not visible at all. It does print true if I switch to a different tab, or minimize the browser, however.
PageVisibility API returns true only if the API is completely hidden. If your window is in the background, but even partially visible, it will return false.
Try putting it in the background, making it smaller than another window, then placing that window overtop. It now returns true.
You may want something like document.hasFocus instead (or some combination).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With