This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

BroadcastChannel.postMessage()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2022년 3월⁩.

BroadcastChannel.postMessage() 는 모든 종류의 Object가 될 수 있는 메세지를 동일한 출처를 가진 모든 브라우징 맥락의 각 수신기에 보냅니다. 메세지는 채널에 바인딩된 각 BroadcastChannel을 대상으로 하는 'message' 이벤트로 전송됩니다.

참고 : 이 기능은 Web Worker에서 사용할 수 있습니다.

구문

js
channel.postMessage(message)

매개변수

message

다른 창으로 전송될 데이터입니다. 데이터는 structured clone 알고리즘을 통해 직렬화됩니다. 즉, 다양한 데이터 객체를 직접 직렬화하지 않고도 안전하게 전송할 수 있습니다.

반환 값

없음.

예외

InvalidStateError DOMException

BroadcastChannel이 이미 닫힌 경우 발생합니다.

DataCloneError DOMException

데이터를 직렬화할 수 없는 경우 발생합니다.

명세서

Specification
HTML
# dom-broadcastchannel-postmessage-dev

브라우저 호환성

같이 보기