W3cubDocs

/DOM

document.onvisibilitychange

The Document.onvisibilitychange property represents the event handler that is called when a visibilitychange event reaches this object.

Syntax

obj.onvisibilitychange = function;
  • function is the name of a user-defined function, without the () suffix or any parameters, or an anonymous function declaration.

Example

document.onvisibilitychange = function() { 
  console.log("Visibility of page has changed!");
}; 

Specifications

Specification Status Comment
Page Visibility (Second Edition)
The definition of 'onvisibilitychange' in that specification.
Recommendation Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 33
33
13
Prefixed
Prefixed Requires the vendor prefix: webkit
Yes 56 10 12.1
12.1
Doesn't fire the visibilitychange event when the browser window is minimized, nor when hidden is set to true.
7
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 4.4.3 33 Yes 56 12.1
12.1
Doesn't fire the visibilitychange event when the browser window is minimized, nor when hidden is set to true.
7 ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/document/onvisibilitychange