PushEvent: PushEvent() コンストラクター
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2023年3月.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
メモ: この機能はサービスワーカー内でのみ利用可能です。
PushEvent() コンストラクターは、新しい PushEvent オブジェクトを生成します。このコンストラクターは、サービスワーカーにのみ公開されていることに注意してください。
構文
js
new PushEvent(type)
new PushEvent(type, options)
引数
type-
文字列で、イベントの名前を示します。 大文字小文字の区別があり、ブラウザーは
pushまたはpushsubscriptionchangeに設定します。 options省略可-
オブジェクトで、
ExtendableEvent()で定義されているプロパティに加えて、以下のプロパティを指定することができます。data-
PushEventに格納したいデータ(もしあれば)。コンストラクターが呼び出されると、結果オブジェクトのPushEvent.dataプロパティには、これらのバイト列を格納した新しいPushMessageDataオブジェクトが設定されます。
返値
新しい PushEvent オブジェクトです。
例
js
const dataInit = {
data: "Some sample text",
};
const myPushEvent = new PushEvent("push", dataInit);
myPushEvent.data.text(); // 'Some sample text' を返す
仕様書
| Specification |
|---|
| Push API> # dom-pushevent-constructor> |
ブラウザーの互換性
Loading…