PAGE VISIBILITY API
A major pain point for web developers is knowing when users are actually interacting with the page. If a page is minimized or hidden behind another tab, it may not make sense to continue functionality such as polling the server for updates or performing animations. The Page Visibility API aims to give developers information about whether or not the page is visible to the user.
The API itself is very simple, consisting of three parts:
document.visibilityState
—A value indicating one of four states:- The page is in a background tab or the browser is minimized.
- The page is in the foreground tab.
- The actual page is hidden, but a preview of the page is visible (such as in Windows 7 when moving the mouse over an icon in the taskbar shows a preview).
- The page is being prerendered off-screen.
visibilitychange
event—This event fires when a document changes from hidden to visible, or vice versa.document.hidden
—A Boolean value indicating if the page is hidden...