This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

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