This topic has not yet been rated - Rate this topic

MessagePort object

Provides an object where messages can be sent and received through a MessageChannel.

HTML5 Web Messaging

Members

The MessagePort object has these types of members:

Events

The MessagePort object has these events.

EventDescription
message

Returns a message from the parent thread to the worker thread, or between two MessagePort objects.

onmessage

Fires when the user sends a cross-document message or a message is sent from a Worker with postMessage.

 

Methods

The MessagePort object has these methods.

MethodDescription
close

Closes a MessagePort from an existing MessageChannel.

postMessage

Sends messages between two connected MessagePorts in a MessageChannel.

start

Allows the MessagePort to begin receiving messages.

 

Standards information

Remarks

Two MessagePort objects are automatically created when a MessageChannel object is created, and are returned by the port1 and port2 properties. Messages are sent from one port are received by the other, and vice versa.

The MessagePort object provides the start method to begin dispatching messages received on the port, and the close method to close and disconnect the port. The postMessage method sends messages through the port.

In Internet Explorer 10, message ports are automatically enabled when a message event is registered with the onmessage property or addEventListener method. This makes it unnecessary to explicitly call the start method under these conditions.

After posting a MessagePort object using postMessage, the MessagePort object is implicitly closed.

For more info, see MessageChannel for a working messaging demo.

See also

Worker
Web worker demo

 

 

Send comments about this topic to Microsoft

Build date: 11/20/2012

Community Additions

ADD
© 2013 Microsoft. All rights reserved.