The Document.visibilityState
read-only property returns the visibility of the document
, that is in which context this element is now visible. It is useful to know if the document is in the background or an invisible tab, or only loaded for pre-rendering. Possible values are:
'visible'
'hidden'
'prerender'
document.hidden
). The document may start in this state, but will never transition to it from another value. Note: browser support is optional.When the value of this property changes, the visibilitychange
event is sent to the Document
.
Typical use of this can be to prevent the download of some assets when the document is solely prerendered, or stop some activities when the document is in the background or minimized.
var string = document.visibilityState
document.addEventListener("visibilitychange", function() { console.log( document.visibilityState ); // Modify behavior... });
Specification | Status | Comment |
---|---|---|
Page Visibility (Second Edition) The definition of 'Document.visibilityState' in that specification. | Recommendation | Initial definition. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 33
|
? | 18
|
10 | 12.1
|
7 |
prerender value
|
Yes | ? | 49 | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 4.4.3 | 33 | ? | 18
|
12.1
|
7 | ? |
prerender value
|
Yes | Yes | ? | 49 | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/document/visibilityState