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

方法

WindowClient 继承来自其父级接口的方法, Client .

WindowClient.focus()

把用户输入聚焦给予当前客户端。

WindowClient.navigate()

将指定 URL 加载到受控客户端页面。

特性

WindowClient 继承来自其父级接口的特性, Client .

WindowClient.focused 只读

A boolean that indicates whether the current client has focus.

WindowClient.visibilityState 只读
Indicates the visibility of the current client. This value can be one of "hidden" , "visible" ,或 "prerender" .

范例

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) {
        client.focus();
        break;
      }
    }
    if (clients.openWindow)
      return clients.openWindow('/');
  }));
});
					

规范

规范 状态 注释
服务工作者
The definition of 'WindowClient' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
WindowClient Chrome 42 Edge ≤18 Firefox 44 注意事项
44 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera ? Safari 不支持 No WebView Android 不支持 No Chrome Android 42 Firefox Android 44 Opera Android ? Safari iOS 不支持 No Samsung Internet Android 4.0
ancestorOrigins Chrome ? Edge ? Firefox ? IE 不支持 No Opera ? Safari 不支持 No WebView Android 不支持 No Chrome Android ? Firefox Android ? Opera Android ? Safari iOS 不支持 No Samsung Internet Android ?
focus Chrome 42 Edge ≤18 Firefox 44 注意事项
44 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera ? Safari 不支持 No WebView Android 不支持 No Chrome Android 42 Firefox Android 44 Opera Android ? Safari iOS 不支持 No Samsung Internet Android 4.0
focused Chrome 42 Edge ≤18 Firefox 44 注意事项
44 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera ? Safari 不支持 No WebView Android 不支持 No Chrome Android 42 Firefox Android 44 Opera Android ? Safari iOS 不支持 No Samsung Internet Android 4.0
navigate Chrome 49 Edge ≤18 Firefox 44 注意事项
44 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera ? Safari 不支持 No WebView Android 不支持 No Chrome Android 49 Firefox Android 44 Opera Android ? Safari iOS 不支持 No Samsung Internet Android 4.0
visibilityState Chrome 42 Edge ≤18 Firefox 44 注意事项
44 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
IE 不支持 No Opera ? Safari 不支持 No WebView Android 不支持 No Chrome Android 42 Firefox Android 44 Opera Android ? Safari iOS 不支持 No Samsung Internet Android 4.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. 服务工作者 API
  2. WindowClient
  3. 特性
    1. focused
    2. visibilityState
  4. 方法
    1. focus()
    2. navigate()
  5. 继承:
    1. Client
  6. Related pages for Service Workers API
    1. 缓存
    2. CacheStorage
    3. Client
    4. Clients
    5. ExtendableEvent
    6. FetchEvent
    7. InstallEvent
    8. Navigator.serviceWorker
    9. NotificationEvent
    10. PeriodicSyncEvent
    11. PeriodicSyncManager
    12. PeriodicSyncRegistration
    13. ServiceWorker
    14. ServiceWorkerContainer
    15. ServiceWorkerGlobalScope
    16. ServiceWorkerRegistration
    17. SyncEvent
    18. SyncManager
    19. SyncRegistration

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1