This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

close

Summary

Disconnects the port, so that it is no longer active.

Method of apis/web-messaging/MessagePortapis/web-messaging/MessagePort

Syntax

 MessagePort.close();

Return Value

No return value

Examples

This example creates a new message channel and uses one of the ports to send a message, which will be received by the other port, then closes the port.

var msgChannel = new MessageChannel();
msgChannel.port1.postMessage('Hello world');
msgChannel.port1.close();

Notes

This method releases the MessagePort from its corresponding MessagePort. After calling the close method, message events will no longer be received on this port and postMessage will no longer post any messages. To continue messaging, you need to create a new MessageChannel and resend one of the ports to the other window or document.

Related specifications

W3C Web Messaging Specification
W3C Candidate Recommendation

Attributions