Firefox Tomorrow

web api instance method

MessagePort: close() method

View on MDN ↗

Available in workers

The close() method of the MessagePort interface disconnects the port, so it is no longer active. This stops the flow of messages to that port.

Syntax

close()

Parameters

None.

Return value

None (undefined).

Examples

In the following code block, you can see a handleMessage handler function, run when a message is sent back to this document using addEventListener.

channel.port1.addEventListener("message", handleMessage);
function handleMessage(e) {
  para.innerHTML = e.data;
  textInput.value = "";
}

channel.port1.start();

You could stop messages being sent at any time using

channel.port1.close();

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also