I have one problem with this API. Everything works good but when I open something over or switch to some application which will be over the browser(i didnt minimize browser, just opened something over it), api doesnt work and hidden status = false. Some on know how to fix it?
-
Sorry, but this question doesn't make any sense without any further context. – Hubert Grzeskowiak Dec 02 '15 at 12:57
-
Speaking briefly, if I press alt+tab - api doesnt work. – user3510544 Dec 02 '15 at 12:58
-
https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API – user3510544 Dec 02 '15 at 12:59
1 Answers
Considering https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API and Mozilla's demo this is intended behaviour. The "focus" that is mentioned in the docs only applies to the tab, not to the whole browser window (if I understand it correctly).
For the sake of completeness, this is from http://www.w3.org/TR/page-visibility/:
On getting, the visibilityState attribute MUST return the DOMString visible if the Document contained by the top level browsing context is at least partially visible at on at least one screen. This is the same condition under which the hidden attribute is set to false.
To accommodate accessibility tools that are typically full screen but still show a view of the page, when applicable, on getting, the visibilityState attribute MAY return the DOMString visible when the User Agent is not minimized but is fully obscured by other applications.
For checking whether the whole window is in focus you could use document.hasFocus() as described here: https://stackoverflow.com/a/3479960/2445864

- 1
- 1

- 15,137
- 5
- 57
- 74
-
You are right, but how ti combine Page Visibility API with $(window).blur/focus? Cause blur/focus have some bugs too. For example when u open tab in background. – user3510544 Dec 02 '15 at 13:04
-
-
As always on SO: try yourself first and ask about specific problems you encounter ;-) – Hubert Grzeskowiak Dec 02 '15 at 13:12