focused
只读特性在
WindowClient
接口是
布尔
that indicates whether the current client has focus.
var myFocused = windowClient.focused;
A
布尔
.
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) {
if(!client.focused)
return client.focus();
}
}
}
if (clients.openWindow)
return clients.openWindow('/');
}));
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'WindowClient: focused' in that specification. |
工作草案 | 初始定义 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
focused
|
Chrome 42 | Edge ≤18 |
Firefox
44
注意事项
|
IE 不支持 No | Opera ? | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 42 | Firefox Android 44 | Opera Android ? | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
见实现注意事项。
WindowClient
focused
visibilityState
缓存
CacheStorage
Client
Clients
ExtendableEvent
FetchEvent
InstallEvent
Navigator.serviceWorker
NotificationEvent
PeriodicSyncEvent
PeriodicSyncManager
PeriodicSyncRegistration
ServiceWorker
ServiceWorkerContainer
ServiceWorkerGlobalScope
ServiceWorkerRegistration
SyncEvent
SyncManager
SyncRegistration