visibilityState
Summary
Returns the visibility state of a webpage.
Property of dom/Documentdom/Document
Syntax
Note: This property is read-only.
var visibilityState = document.visibilityState;
Return Value
Returns an object of type StringString
The current visibility state of the document, one of "hidden", "visible", "prerender", "unloaded".
Examples
var timer = 0;
var PERIOD_VISIBLE = 1000;
var PERIOD_NOT_VISIBLE = 60000;
function onLoad() {
timer = setInterval(checkEmail, (document.hidden) ? PERIOD_NOT_VISIBLE : PERIOD_VISIBLE);
if(document.addEventListener) document.addEventListener("visibilitychange", visibilityChanged);
}
function visibilityChanged() {
clearTimeout(timer);
timer = setInterval(checkEmail, (document.hidden) ? PERIOD_NOT_VISIBLE : PERIOD_VISIBLE);
}
function checkEmail() {
// Check server for new messages
}
window.onload = onLoad;
Notes
Use the visibilitychange property to track changes to the visibility state.
Related specifications
- Page Visibility
- Recommendation
See also
Related articles
Performance
visibilityState
Related pages
- hiddenhidden
- visibilitychangevisibilitychange
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]