MessageEvent.MessageEvent()

Draft
This page is not complete.

The MessageEvent() constructor creates a new MessageEvent object instance.

Syntax

var messageEvent = new MessageEvent(type, init);

Parameters

type
The type of MessageEvent that will be created. This can be one of XXX

init Optional

A dictionary object that can contain the following properties:

  • data: The data you want contained in the MessageEvent. This can be of any data type, and will default to null if not specified.
  • origin: A USVString representing the origin of the message emitter. This defaults to an empty string ("") if not specified.
  • lastEventId: A DOMString representing a unique ID for the event. This defaults to an empty string ("") if not specified.
  • source: An MessageEventSource (which can be a WindowProxy, MessagePort, or ServiceWorker object) representing the message emitter. This defaults to null if not set.
  • ports: An array of MessagePort objects representing the ports associated with the channel the message is being sent through (where appropriate, e.g. in channel messaging or when sending a message to a shared worker). This defaults to an empty array ([]) if not specified.

Example

var myMessage = new MessageEvent('worker', {
  data : 'hello'
});

Specifications

Specification Status Comment
Unknown
The definition of 'MessageEvent' in that specification.
Unknown Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox Full support 4IE Full support 9Opera ? Safari Full support 10WebView Android ? Chrome Android ? Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS Full support 3Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also

  • ExtendableMessageEvent — similar to this interface but used in interfaces that needs to give more flexibility to authors.

Document Tags and Contributors

Contributors to this page: fscholz, chrisdavidmills
Last updated by: fscholz,