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
MessageEventthat will be created. This can be one of XXX -
initOptional -
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 tonullif not specified.origin: AUSVStringrepresenting the origin of the message emitter. This defaults to an empty string ("") if not specified.lastEventId: ADOMStringrepresenting a unique ID for the event. This defaults to an empty string ("") if not specified.source: AnMessageEventSource(which can be aWindowProxy,MessagePort, orServiceWorkerobject) representing the message emitter. This defaults tonullif not set.ports: An array ofMessagePortobjects 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 |
|---|---|---|
| HTML Living Standard The definition of 'MessageEvent()' in that specification. |
Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
MessageEvent() constructor | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera ? | Safari Full support 4 | WebView Android Full support 37 | Chrome Android Full support 18 | Firefox Android ? | Opera Android ? | Safari iOS Full support 3 | Samsung Internet Android Full support 1.0 |
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.
