BroadcastChannel - patrickcole/learning GitHub Wiki
BroadcastChannel API
Allows webpages to communicate with other windows, tabs, iframes within the same origin
const channel = new BroadcastChannel('uniqueid');
channel.onmessage = ( event ) => {
// event.data
if ( event.data === "triggeredEventTitle" ) {
// do something!
}
}
function triggerUpdate() {
channel.postMessage('triggeredEventTitle');
}
Data for a BroadcastChannel message can be:
- All primitive types except Symbols
- Boolean and String objects
- Dates
- Regular Expressions
- Blobs
- Files, FileLists
- ArrayBuffers, ArrayBufferViews
- ImageBitmaps, ImageDatas
- Arrays, Objects, Maps and Sets
To close a BroadcastChannel, simply call the .close()
method:
channel.close();