浏览器标签页被隐藏或显示的时候会触发visibilitychange事件.

概述

Specification
Page Visibility (Second Edition)
Interface
event
Bubbles
Yes
Cancelable
No
Target
Document
Default Action
None

属性

Property Type Description
target 只读 EventTarget The event target (the topmost target in the DOM tree).
type 只读 DOMString The type of event.
bubbles 只读 Boolean Whether the event normally bubbles or not.
cancelable 只读 Boolean Whether the event is cancellable or not.

例子

document.addEventListener("visibilitychange", function() {
  console.log( document.visibilityState );
});

规范

规范 状态 注释
W3C Page Visibility API Recommendation

浏览器兼容性

No compatibility data found. Please contribute data for "api.Document.visibilitychange" (depth: 1) to the MDN compatibility data repository.

相关链接

文档标签和贡献者

此页面的贡献者: 1v9, irenesmith, mdnwebdocs-bot, fscholz, ziyunfei
最后编辑者: 1v9,