Open taoliujun opened 4 months ago
MDN: https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API
Broadcast Channel可以在同源情况下,在一种浏览器的不同窗口、标签页、frame中简单通信。
传入频道名称,返回实例,包含了message事件来监听消息、postMessage方法来发送信息。
message
postMessage
示例:https://taoliujun.github.io/example/web-api/Broadcast_Channel_API/index.html
web api的跨页通信标准有好几个,Broadcast Channel是其中较为明确和简单的一个。在多页web中很有用,比如通知所有页面退出登录。
Broadcast Channel
Broadcast Channel可以在同源情况下,在一种浏览器的不同窗口、标签页、frame中简单通信。
接口
BroadcastChannel
传入频道名称,返回实例,包含了
message
事件来监听消息、postMessage
方法来发送信息。示例
示例:https://taoliujun.github.io/example/web-api/Broadcast_Channel_API/index.html