1. 9 コミュニケーション
    1. 9.1 MessageEventインターフェイス

9 コミュニケーション

9.1 MessageEventインターフェイス

サーバー送信イベントweb socketscross-document messagingchannel messaging、および broadcast channelsのメッセージは、messageイベントにMessageEventインターフェイスを使用する:

event . data

MessageEvent/data

Support in all current engines.

Firefox4+Safari4+Chrome1+
OperaYesEdge79+
Edge (Legacy)12+Internet Explorer9+
Firefox AndroidYesSafari iOS3+Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes

Returns the data of the message.

event . origin

MessageEvent/origin

Support in all current engines.

Firefox4+Safari4+Chrome1+
OperaYesEdge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android4+Safari iOS3+Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes

Returns the origin of the message, for server-sent events and cross-document messaging.

event . lastEventId

MessageEvent/lastEventId

Support in all current engines.

Firefox4+Safari4+Chrome1+
OperaYesEdge79+
Edge (Legacy)17+Internet Explorer9+
Firefox AndroidYesSafari iOS3+Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes

Returns the last event ID string, for server-sent events.

event . source

MessageEvent/source

Support in all current engines.

Firefox55+SafariYesChromeYes
OperaYesEdgeYes
Edge (Legacy)12+Internet ExplorerNo
Firefox Android55+Safari iOSYesChrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes

Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects.

event . ports

MessageEvent/ports

Support in all current engines.

Firefox4+Safari4+Chrome1+
OperaYesEdge79+
Edge (Legacy)12+Internet Explorer9+
Firefox AndroidYesSafari iOS3+Chrome AndroidYesWebView AndroidYesSamsung InternetYesOpera AndroidYes

Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.

Various APIs (e.g., WebSocket, EventSource) use the MessageEvent interface for their message event without using the MessagePort API.