The Wayback Machine - https://web.archive.org/web/20150919065503/https://developer.mozilla.org/zh-CN/docs/Web/API/WindowClient

WindowClient

4 位贡献者:

这篇文章需要技术审查。

我们的志愿者还没有将这篇文章翻译为 中文 (简体) 。加入我们帮助完成翻译!

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

The WindowClient interface of the ServiceWorker API represents the scope of a service worker client that is a document in a browser context, controlled by an active worker. The service worker client independently selects and uses a service worker for its own loading and sub-resources.

Methods

WindowClient inherits methods from its parent interface, Client.

WindowClient.focus()
Gives user input focus to the current client. 

Properties

WindowClient inherits properties from its parent interface, Client.

WindowClient.focused Read only
A boolean that indicates whether the current client has focus.
WindowClient.visibilityState Read only
Indicates the visibility of the current client. This value can be one of hidden, visible, prerender, or unloaded.

Example

self.addEventListener('notificationclick', function(event) {
  console.log('On notification click: ', event.notification.tag);
  event.notification.close();

  // This looks to see if the current is already open and
  // focuses if it is
  event.waitUntil(clients.matchAll({
    type: "window"
  }).then(function(clientList) {
    for (var i = 0; i < clientList.length; i++) {
      var client = clientList[i];
      if (client.url == '/' && 'focus' in client)
        return client.focus();
    }
    if (clients.openWindow)
      return clients.openWindow('/');
  }));
});

Specifications

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

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 42.0 ? Not supported ? Not supported
Feature Android Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? ? ? Not supported ? Not supported 42.0

See also

文档标签和贡献者

向此页面作出贡献: Sebastianz, kscarfone, jpmedley, chrisdavidmills
最后编辑者: Sebastianz,