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 18
Notes
Full support 18
Notes
Notes Before Edge 18, this event handler attribute was not supported; however, the event itself was supported since Edge 12. The event can be listened to via document.addEventListener('visibilitychange', function() {});.
Firefox Full support 56IE No support No
Notes
No support No
Notes
Notes This event handler attribute is not supported; however, the event itself is supported since IE 10. The event can be listened to via document.addEventListener('visibilitychange', function() {});.
Opera 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 Partial support 10.1
Notes
Partial support 10.1
Notes
Notes Doesn't fire the visibilitychange event when navigating away from a document, so also include code to check for the pagehide event (which does fire for that case in all current browsers). See WebKit bugs 116769, 151234, 151610, and 194897.
Notes Before Safari 10.1, this event handler attribute was not supported; however, the event itself was supported since Safari 7. The event can be listened to via document.addEventListener('visibilitychange', function() {});.
WebView 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 Partial support 10.3
Notes
Partial support 10.3
Notes
Notes Doesn't fire the visibilitychange event when navigating away from a document, so also include code to check for the pagehide event (which does fire for that case in all current browsers). See WebKit bugs 116769, 151234, 151610, and 194897.
Notes Before Safari iOS 10.3, this event handler attribute was not supported; however, the event itself was supported since Safari iOS 7. The event can be listened to via document.addEventListener('visibilitychange', function() {});.
Samsung Internet Android Full support 2.0

Legend

Full support  
Full support
Partial support  
Partial support
No support  
No support
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

另见