WindowClient.visibilityState

您正在阅读此内容的英文版本,因为该语系尚未翻译。 帮助我们翻译此文章吧!

The visibilityState read-only property of the WindowClient interface indicates the visibility of the current client. This value can be one of hidden, visible, prerender, or unloaded.

Syntax

myVisState = WindowClient.visibilityState;

Value

A DOMString.

Example

event.waitUntil(clients.matchAll({
    type: "window"
  }).then(function(clientList) {
    for (let i = 0; i < clientList.length; i++) {
      let client = clientList[i];
      if (client.url == '/' && 'focus' in client) {
        if (client.visibilityState === 'hidden')
          return client.focus();
        }
      }
    }

    if (clients.openWindow) {
      return clients.openWindow('/');
    }
  }));
});

Specifications

Specification Status Comment
Service Workers
The definition of 'visibilityState' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
visibilityState
Experimental
Chrome Full support 42Edge Full support YesFirefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 and 52 Extended Support Releases (ESR).
IE No support NoOpera ? Safari No support NoWebView Android No support NoChrome Android Full support 42Firefox Android Full support 44Opera Android ? Safari iOS No support NoSamsung Internet Android Full support 4.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.