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/pushevent/index.html | 101 ++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 files/ja/web/api/pushevent/index.html (limited to 'files/ja/web/api/pushevent/index.html') diff --git a/files/ja/web/api/pushevent/index.html b/files/ja/web/api/pushevent/index.html new file mode 100644 index 0000000000..ddbf3ac4a8 --- /dev/null +++ b/files/ja/web/api/pushevent/index.html @@ -0,0 +1,101 @@ +--- +title: PushEvent +slug: Web/API/PushEvent +tags: + - API + - ExtendableEvent + - Interface + - Offline + - Push + - Push API + - Reference + - Service Workers + - Workers +translation_of: Web/API/PushEvent +--- +

{{APIRef("Push API")}}{{SeeCompatTable()}}

+ +

Push APIPushEvent インターフェースは、受け取ったプッシュメッセージを表します。このイベントは、{{domxref("ServiceWorker")}} の グローバルスコープに送信されます。これは、アプリケーションサーバーから {{domxref("PushSubscription")}} に送信された情報を含みます。

+ +

コンストラクタ

+ +
+
{{domxref("PushEvent.PushEvent()")}}
+
新しい PushEvent オブジェクトを生成します。
+
+ +

プロパティ

+ +

親である {{domxref("ExtendableEvent")}} からプロパティを継承しています。追加プロパティ:

+ +
+
{{domxref("PushEvent.data")}} {{readonlyinline}}
+
{{domxref("PushSubscription")}} に送信されたデータを含む {{domxref("PushMessageData")}} オブジェクトへの参照を返します。
+
+ +

メソッド

+ +

親である {{domxref("ExtendableEvent")}} からメソッドを継承しています。

+ +

+ +

次の例は、PushEvent からデータを取得して、すべての service worker クライアントで表示しています。

+ +
self.addEventListener('push', function(event) {
+  if (!(self.Notification && self.notification.permission === 'granted')) {
+   return;
+ }
+
+ var data = {};
+ if (event.data) {
+   data = event.data.json();
+ }
+ var title = data.title || "Something Has Happened";
+ var message = data.message || "Here's something you might want to check out.";
+ var icon = "images/new-notification.png";
+
+ var notification = new self.Notification(title, {
+   body: message,
+   tag: 'simple-push-demo-notification',
+   icon: icon
+ });
+
+ notification.addEventListener('click', function() {
+   if (clients.openWindow) {
+     clients.openWindow('https://example.blog.com/2015/03/04/something-new.html');
+   }
+ });
+});
+
+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('Push API','#the-push-event','PushEvent')}}{{Spec2('Push API')}}初期定義。
+ +

ブラウザー実装状況

+ +
+ + +

{{Compat("api.PushEvent")}}

+
+ +

関連項目

+ + -- cgit v1.2.3-54-g00ecf