Document:hidden 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Document.hidden 只读属性返回一个表示页面是否被视为隐藏的布尔值。

Document.visibilityState 属性提供了另一种确定页面是否隐藏的方法。

布尔值,如果页面隐藏则为 true,否则为 false

示例

js
document.addEventListener("visibilitychange", () => {
  console.log(document.hidden);
  // 修改行为……
});

规范

Specification
HTML
# dom-document-hidden

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
hidden

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

参见