通过调用 BroadcastChannel.close()
方法,可以马上断开其与对应频道的关联,并让其被垃圾回收。这是必要的步骤,因为浏览器没有其它方式知道频道不再被需要。
Note: 此特性在 Web Worker 中可用。
语法
var str = channel
.close();
示例
// 连接到指定频道
var bc = new BroadcastChannel('test_channel');
// 其它操作 (如: postMessage, …)
// 当完成后,断开与频道的连接
bc.close();
规范
规范 | 状态 | 备注 |
---|---|---|
HTML Living Standard BroadcastChannel.close() |
Living Standard | Initial definition. |
浏览器兼容性
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
另见
BroadcastChannel
, the interface it belongs to.