This page was translated from English by the community.Learn more and join the MDN Web Docs community.
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월.
참고 : This feature is only available inService Workers.
Push API의PushEvent 인터페이스는 수신된 푸시 메시지를 나타냅니다. 이 이벤트는ServiceWorker의전역 범위로 전송됩니다. 애플리케이션 서버에서PushSubscription로 전송된 정보를 포함합니다.
In this article
생성자
PushEvent()새로운
PushEvent객체를 생성합니다.
인스턴스 속성
부모인ExtendableEvent에서 속성을 상속받습니다. 다음은 추가 속성입니다.
PushEvent.data읽기 전용PushSubscription으로 전송된 데이터를 포함하는PushMessageData객체에 대한 참조를 반환합니다.
인스턴스 메서드
부모인ExtendableEvent에서 메서드를 상속받습니다.
예제
다음 예제는PushEvent에서 데이터를 가져와 서비스 워커의 모든 클라이언트에 표시합니다.
js
self.addEventListener("push", (event) => { if (!(self.Notification && self.Notification.permission === "granted")) { return; } const data = event.data?.json() ?? {}; const title = data.title || "Something Has Happened"; const message = data.message || "Here's something you might want to check out."; const icon = "images/new-notification.png"; const notification = new self.Notification(title, { body: message, tag: "simple-push-demo-notification", icon, }); notification.addEventListener("click", () => { clients.openWindow( "https://example.blog.com/2015/03/04/something-new.html", ); });});명세서
| Specification |
|---|
| Push API> # pushevent-interface> |