Document.hidden

Document.hidden (只读属性)返回布尔值,表示页面是(true)否(false)隐藏。

语法

var string = document.hidden

例子

document.addEventListener("visibilitychange", function() {
  console.log( document.hidden );
  // Modify behavior...
});

规范

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

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
hiddenChrome Full support 33
Full support 33
Full support 13
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 12Firefox Full support 18
Notes
Full support 18
Notes
Notes Since Firefox 56 it also returns true on Mac when the window is completely hidden by another non-translucent application.
No support 10 — 52
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Full support 10Opera Full support 12.1Safari Full support 7WebView Android Full support YesChrome Android Full support 33
Full support 33
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android Full support 18
Notes
Full support 18
Notes
Notes Since Firefox 56 it also returns true on Mac when the window is completely hidden by another non-translucent application.
No support 10 — 52
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Full support 12.1Safari 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.