MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey

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 compatibility

  
Feature Firefox (Gecko) Chrome Edge Internet Explorer Opera Safari
Basic support 56 (56) 13 webkit
33
(Yes) 10 12.10[1] 6.1
  
Feature Firefox Mobile (Gecko) Android Edge IE Mobile Opera Mobile Safari Mobile
onselectionchange 56.0 (56) 4.4 webkit (Yes) ? 12.10[1] 7

[1] Doesn't fire the visibilitychange event when the browser window is minimized, nor set hidden to true.

See also

Document Tags and Contributors

 Contributors to this page: chrisdavidmills
 Last updated by: chrisdavidmills,