1. 開発者向けのウェブ技術
  2. Web API
  3. WindowClient
  4. focused

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

WindowClient: focused プロパティ

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2018年4月以降、すべてのブラウザーで利用可能です。

focusedWindowClient インターフェイスの読み取り専用プロパティで、現在のクライアントにフォーカスがあるかどうかを示す論理値です。

論理値です。

js
self.addEventListener("notificationclick", (event) => {
 console.log("On notification click: ", event.notification.tag);
 event.notification.close();
 // これは、クライアントが既に開いているかどうかを確認し、
 // 開いている場合にフォーカスを合わせます
 event.waitUntil(
 clients
 .matchAll({
 type: "window",
 })
 .then((clientList) => {
 for (const client of clientList) {
 if (client.url === "/" && "focus" in client) {
 if (!client.focused) return client.focus();
 }
 }
 if (clients.openWindow) return clients.openWindow("/");
 }),
 );
});

仕様書

仕様書
Service Workers Nightly
# client-focused

ブラウザーの互換性

MDN の改良に協力

協力方法を知る

このページは MDN の貢献者によって に最終更新されました。

AltStyle によって変換されたページ (->オリジナル) /