From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/windowclient/focused/index.html | 73 ++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 files/ja/web/api/windowclient/focused/index.html (limited to 'files/ja/web/api/windowclient/focused') diff --git a/files/ja/web/api/windowclient/focused/index.html b/files/ja/web/api/windowclient/focused/index.html new file mode 100644 index 0000000000..31eefaf0dd --- /dev/null +++ b/files/ja/web/api/windowclient/focused/index.html @@ -0,0 +1,73 @@ +--- +title: WindowClient.focused +slug: Web/API/WindowClient/focused +tags: + - API + - Property + - Reference + - Service Workers + - ServiceWorker + - WindowClient + - focused +translation_of: Web/API/WindowClient/focused +--- +
{{APIRef("Service Workers API")}}
+ +

{{domxref("WindowClient")}} インターフェイスの focused 読み取り専用プロパティは、現在のクライアントにフォーカスがあるかどうかを示す {{jsxref("Boolean")}} です。

+ +

構文

+ +
var myFocused = windowClient.focused;
+ +

+ +

{{jsxref("Boolean")}}。

+ +

+ +
self.addEventListener('notificationclick', function(event) {
+  console.log('On notification click: ', event.notification.tag);
+  event.notification.close();
+
+  // これは、クライアントが既に開いているかどうかを確認し、
+  // 開いている場合にフォーカスを合わせます
+  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('/');
+  }));
+});
+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('Service Workers', '#dom-windowclient-focused', 'WindowClient: focused')}}{{Spec2('Service Workers')}}初期定義
+ +

ブラウザーの互換性

+ +
+ + +

{{Compat("api.WindowClient.focused")}}

+
-- cgit v1.2.3-54-g00ecf