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.
Note: This feature is available in Web 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.
Note: This feature is available in Web Workers
js
close()
None.
None (undefined
).
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
.
js
channel.port1.addEventListener("message", handleMessage, false); function handleMessage(e) { para.innerHTML = e.data; textInput.value = ""; } channel.port1.start();
You could stop messages being sent at any time using
js
channel.port1.close();
Specification |
---|
HTML Standard # dom-messageport-close-dev |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
close |
2 | 12 | 41 | 10 | 10.6 | 5 | 4.4 | 18 | 41 | 11 | 4.2 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/close