浏览器标签页被隐藏或显示的时候会触发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  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome (Webkit) Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13 webkit 10 (10) moz
18 (18)
10 ms 12.10[*] 未实现
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 未实现 10.0 (10) moz
18.0 (18)
? 12.10[*] 未实现

[*] 的意思是该浏览器在最小化时不触发visibilitychange事件,也不将hidden属性设置为true.

相关链接

文档标签和贡献者

此页面的贡献者: fscholz, ziyunfei
最后编辑者: fscholz,