MessagePort: close() method
Channel Messaging API
Channel Messaging API
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
EventTarget.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();