浏览器标签页被隐藏或显示的时候会触发visibilitychange事件.
概述
- Specification
- Page Visibility API
- 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 |
Does the event normally bubble? |
cancelable 只读 |
boolean |
Is it possible to cancel the event? |
例子
document.addEventListener("visibilitychange", function() {
console.log( document.visibilityState );
});
规范
| 规范 | 状态 | 注释 |
|---|---|---|
| W3C Page Visibility API | Recommendation |
浏览器兼容性
| 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.