focus()
方法在
WindowClient
interface gives user input focus to the current client and returns a
Promise
that resolves
to the existing
WindowClient
.
windowClient.focus().then(function(windowClient) {
// do something with your WindowClient once it has been focused
});
None.
A
Promise
that resolves to the existing
WindowClient
.
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('/');
}));
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'focus()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
focus
|
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
focus()
navigate()
缓存
CacheStorage
Client
Clients
ExtendableEvent
FetchEvent
InstallEvent
Navigator.serviceWorker
NotificationEvent
PeriodicSyncEvent
PeriodicSyncManager
PeriodicSyncRegistration
ServiceWorker
ServiceWorkerContainer
ServiceWorkerGlobalScope
ServiceWorkerRegistration
SyncEvent
SyncManager
SyncRegistration