Document.onvisibilitychange

Document.onvisibilitychange 是一个事件处理方法,它将在该对象的 visibilitychange事件被触发时调用。

Syntax

obj.onvisibilitychange = function;
  • function 是一个用户定义的方法的名字(而非带()和任何参数的函数调用),或者匿名函数的申明。

例子

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

标准

Specification Status Comment
Page Visibility (Second Edition)
onvisibilitychange
Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
onvisibilitychangeChrome Full support 33
Full support 33
Full support 13
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 18Firefox Full support 56IE Full support 10Opera Full support 12.1
Notes
Full support 12.1
Notes
Notes Doesn't fire the visibilitychange event when the browser window is minimized, nor when hidden is set to true.
Safari Full support 7WebView Android Full support 4.4.3Chrome Android Full support 33Firefox Android Full support 56Opera Android Full support 12.1
Notes
Full support 12.1
Notes
Notes Doesn't fire the visibilitychange event when the browser window is minimized, nor when hidden is set to true.
Safari iOS Full support 7Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

另见