博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BroadcastChannel API
阅读量:2503 次
发布时间:2019-05-11

本文共 1219 字,大约阅读时间需要 4 分钟。

The Channel Messaging API is a great way to send 1-to-1 messages from a window to an iframe, from a window to a Web Worker, and so on.

Channel Messaging API是一种从窗口向iframe,从窗口向Web Worker等发送一对一消息的好方法。

The BroadcastChannel API can be used to send 1-to-many messages, communicating to multiple entities at the same time.

BroadcastChannel API可用于发送一对多消息,同时与多个实体进行通信。

You start by initializing a BroadcastChannel object:

首先初始化一个BroadcastChannel对象:

const channel = new BroadcastChannel ( 'thechannel' )

To send a message on the channel you use the postMessage() method:

要在频道上发送消息,请使用postMessage()方法:

channel . postMessage ( 'Hey!' )

A message can be any of those supported values:

消息可以是以下任何受支持的值:

  • All primitive types, excluding symbols

    所有原始类型,不包括符号
  • Object literals

    对象文字
  • , , objects

    , , 对象

  • , , objects

    , , 对象

  • , objects

    , 对象

  • objects

    对象

  • ImageData objects

    ImageData对象
  • and objects

    和对象

To receive messages from the channel, listen to the message event:

要从频道接收消息,请收听message事件:

channel . onmessage = event => {  console . log ( 'Received' , event . data )}

This event is fired for all listeners, except the one that is sending the message.

除发送消息的侦听器之外的所有侦听器均触发此事件。

You can close the channel using:

您可以使用以下方法关闭频道:

channel . close ()

翻译自:

转载地址:http://ioqgb.baihongyu.com/

你可能感兴趣的文章
20189320《网络攻防》第五周作业
查看>>
2019.1.18笔记
查看>>
删除了Ubuntu之后,不能正常进入到Win7系统之中的解决办法
查看>>
写一个正则表达式匹配手机号
查看>>
Linux试题
查看>>
TableLock插件
查看>>
java 获取页面中的 a 标签 的 href 实例
查看>>
Knowledge Point 20180305 详解精度问题
查看>>
开发 Windows 8 Bing地图应用(4)
查看>>
mysql-python安装时mysql_config not found
查看>>
loadrunner 场景设计-添加Unix、Linux Resources计数器
查看>>
Python 基于python编写一些算法程序等
查看>>
Python 一键commit文件、目录到SVN服务器
查看>>
毕业5年决定你的命运 ----值得所有不甘平庸的人看看
查看>>
基于Python的接口自动化-01
查看>>
前台返回json数据的常用方式+常用的AJAX请求后台数据方式
查看>>
spring boot下MultipartHttpServletRequest如何提高上传文件大小的默认值
查看>>
css继承和边框圆角 及 写三角形
查看>>
编译opencv有关cuda的代码
查看>>
spring quartz job autowired 出错 null pointer
查看>>