EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

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

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

message

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

 

Methods

The MessagePort object has these methods.

MethodDescription
addEventListener

Registers an event handler for the specified event type.

close

Closes a MessagePort from an existing MessageChannel.

dispatchEvent

Sends an event to the current element.

postMessage

Sends messages between two connected MessagePorts in a MessageChannel.

removeEventListener

Removes an event handler that the addEventListener method registered.

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

 

 

표시:
© 2014 Microsoft