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


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


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


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

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Opera Safari
Basic support 13 webkit
(Yes) 56 (56) 12.10[1] 6.1
Feature Android Webview Chrome for Android Edge Firefox Mobile (Gecko) Opera Mobile Safari Mobile
Basic support 33 33 (Yes) 56.0 (56) 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: jpmedley, chrisdavidmills
 Last updated by: jpmedley,