The visibilitychange
event is fired when the content of a tab has become visible or has been hidden.
General infoEdit
- Specification
- Page Visibility API
- Interface
event
- Bubbles
- Yes
- Cancelable
- No
- Target
Document
- Default Action
- None
PropertiesEdit
Property | Type | Description |
---|---|---|
target Read only |
EventTarget |
The event target (the topmost target in the DOM tree). |
type Read only |
DOMString |
The type of event. |
bubbles Read only |
boolean |
Does the event normally bubble? |
cancelable Read only |
boolean |
Is it possible to cancel the event? |
ExampleEdit
document.addEventListener("visibilitychange", function() {
console.log( document.visibilityState );
});
SpecificationsEdit
Specification | Status | Comment |
---|---|---|
Page Visibility API The definition of 'visibilitychange' in that specification. |
Recommendation |
Browser compatibilityEdit
[1] Doesn't fire the visibilitychange
event when the browser window is minimized, nor set hidden
to true
.