PushEvent: PushEvent() コンストラクター
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (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 |
ブラウザーの互換性
BCD tables only load in the browser