当前位置: 首页 > news >正文

南京中建乡旅建设投资有限公司网站哈尔滨企业网站seo

南京中建乡旅建设投资有限公司网站,哈尔滨企业网站seo,工程建设信息官方网站,网站后期维护管理BroadcastChannel与MessageChannel BroadcastChannel BroadcastChannel以广播的形式进行通信 BroadcastChannel用于创建浏览器标签页之间的通信 使用BroadcastChannel的浏览器标签页面必须要遵循同源策略 页面1使用BroadcastChannel创建一个频道,页面2使用Broadc…

BroadcastChannel与MessageChannel

BroadcastChannel

BroadcastChannel以广播的形式进行通信
BroadcastChannel用于创建浏览器标签页之间的通信
使用BroadcastChannel的浏览器标签页面必须要遵循同源策略

页面1使用BroadcastChannel创建一个频道,页面2使用BroadcastChannel链接频道,页面1与页面2即可通信。

let m1=new BroadcastChannel("channel");//入参是创建或链接的频道名,没有频道则创建通信频道,有频道则进入频道
m1.postMessage('data数据');//以广播的形式向其他链接频道的标签发送消息
m1.onmessage=(e)=>{console.log(e);//接收频道发送过来的消息
}

实例

//BroadcastChannel1.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><a href="http://127.0.0.1:8080/BroadcastChannel2.html" target="_blank">打开新的标签页</a><button onclick="send()">点击</button><script>const m1=new BroadcastChannel('one');function send(){m1.postMessage({data:"123123"})}m1.onmessage=(e)=>{console.log('e=>',e);}</script>
</body>
</html>//BroadcastChannel2.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><script>const m1=new BroadcastChannel('one');m1.onmessage=(e)=>{console.log("e=>",e)}m1.postMessage('adad')</script>
</body>
</html>

MessageChannel

MessageChannel以通道的形式进行传值
MessageChannel无法跨越浏览器标签页通信,只能在当前标签页进行通信

MessageChannel的对象只有两个端口:prot1、port2
在这里插入图片描述

let m=new MessageChannel();//创建消息通道
//m有两个端口:prot1、prot2
m.port1.postMessage("data数据");//prot1数据肯定是向prot2发送,同理prot2也只能向prot1发送数据
m.prot2.onmessage=(e)=>{console.log(e);//prot2接收prot1发送的数据
}

实例

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><script>let m=new MessageChannel();m.port1.postMessage("data");m.port2.onmessage=(e)=>{console.log(e);}</script>
</body>
</html>

Tips:使用MessageChannel传递的引用数据类型是深拷贝。也就是改变端口数据的值,发送端的数据不会改变。

http://www.mmbaike.com/news/43207.html

相关文章:

  • 哪些网站做外贸效果好视频号链接怎么获取
  • 因脉网站建设公司怎么呀韩国石家庄seo网络推广
  • 记事本做网站的流程济南网站制作平台
  • 把网站做成微信小程序如何做电商新手入门
  • 做视频网站需要什么空间湖南网站制作公司
  • pc官方网站11月将现新冠感染高峰
  • 省示范院校建设网站seo实战
  • 怎样看网站的建设时间百度公司招聘岗位
  • 安徽做网站的公司有哪些青岛seo建站
  • 有哪些做场景秀的网站广州百度推广电话
  • 关于企业网站建设的必要性seo课程培训机构
  • 宁夏建设工程招投标管理中心网站域名搜索引擎入口
  • 网站设计尺寸规范青岛seo搜索优化
  • 涿州做网站seo域名如何优化
  • 手机网页qq登录公司要做seo
  • 昆明做网站排名宁德seo培训
  • 做网站接私活南宁网站公司
  • 建立网站的程序营销策划主要做些什么
  • 前端做图表的网站免费推广网站大全
  • 增加网站和接入备案新网域名查询
  • zblog建站教程seo排名点击软件运营
  • 免费做调查的网站有哪些深圳市seo网络推广哪家好
  • 做的网站腾讯云1元域名
  • 客户管理系统哪家好长安网站优化公司
  • 做网站的流程徐州seo网站推广
  • 乡村旅游网站的建设sem竞价代运营公司
  • 响应式企业展示型网站南宁seo计费管理
  • 济南建设网站哪里好网站推广如何做
  • 中文软件开发平台正版搜索引擎优化
  • 哪个网站可以兼职做效果图西安百度关键词推广