I volontari di MDN non hanno ancora tradotto questo articolo in Italiano. Unisciti a noi e traducilo tu stesso.
Puoi anche consultare l’articolo in English (US).

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'
The page content may be at least partially visible. In practice this means that the page is the foreground tab of a non-minimized window.
'hidden'
The page content is not visible to the user. In practice this means that the document is either a background tab or part of a minimized window, or the OS screen lock is active.
'prerender'
The page content is being prerendered and is not visible to the user (considered hidden for purposes of 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.

Syntax

var string = document.visibilityState

Examples

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

Specifications

Specification Status Comment
Page Visibility (Second Edition)
The definition of 'Document.visibilityState' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 33
Full support 33
Full support 13
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge ? Firefox Full support 18
Full support 18
No support 10 — 52
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
IE Full support 10Opera Full support 12.1
Notes
Full support 12.1
Notes
Notes Doesn't fire the visibilitychange event when the browser window is minimized, nor when hidden is set to true.
Safari Full support 7WebView Android Full support 4.4.3Chrome Android Full support 33Edge Mobile ? Firefox Android Full support 18
Full support 18
No support 10 — 52
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
Opera Android Full support 12.1
Notes
Full support 12.1
Notes
Notes Doesn't fire the visibilitychange event when the browser window is minimized, nor when hidden is set to true.
Safari iOS Full support 7Samsung Internet Android ?
prerender value
DeprecatedNon-standard
Chrome Full support YesEdge ? Firefox Full support 49IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 49Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

Tag del documento e collaboratori

Hanno collaborato alla realizzazione di questa pagina: SaschaNaz, fscholz, Tigt, adyouri, MarcusJTW, teoli
Ultima modifica di: SaschaNaz,