This page is Almost Ready

Notice: The WebPlatform project has been discontinued when the Stewards partnership agreement ended in September 2015. This site has been frozen, and the assets we have created will remain.

visibilitychange

Summary

Set the visibility state of an element

Property of dom/Documentdom/Document

Syntax

var result = element.visibilitychange;
element.visibilitychange = value;

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

Remarks

This event is not triggered when it is registered.

Syntax

Event handler parameters

This method has no parameters.

Related specifications

Page Visibility
Recommendation

See also

Related articles

Performance

Attributions