当前位置:网站首页>Communication between browser tab pages
Communication between browser tab pages
2022-07-01 22:24:00 【yanling. zhang】
Reprint :https://zhuanlan.zhihu.com/p/63422027
1. scene 1: Two need to interact tab Pages have dependencies – postMessage
Such as A Page through JavaScript Of window.open open B page , perhaps B Page passing iframe Embedded in A page , This situation is the simplest , Can pass HTML5 Of window.postMessage API Complete communication , because postMessage The function is bound to window Under the global object , Therefore, there must be a page in the communication page ( Such as A page ) You can get another page ( Such as B page ) Of window object , Only in this way can one-way communication be completed ;B No need to get the page A Page window object , if necessary B Page face A Page communication , Only need B Page listening message event , Get the source object , The object is A page window References to objects :
2. scene 2: The two open pages belong to the same category – storage
To achieve two unrelated homologies tab Page correspondence , You can use a more ingenious way :localstorage.localStorage The storage of follows the same origin strategy , So two homologous tab Pages can be shared through this localStorage To achieve communication , By agreement localStorage One of the itemName, Based on this key The content of the value is as “ Shared hard disk ” Means of communication .
HTML5 Provides storage event , adopt window Object listening storage event , Listen localStorage Object change events ( Include item The addition of 、 Modification and deletion ). therefore , An efficient communication mechanism can be achieved through events .
边栏推荐
- Show member variables and methods in classes in idea
- Separate the letters and numbers in the string so that the letters come first and the array comes last
- NIO与传统IO的区别
- Tops, the unit of computing power of the processor, can be carried out 1 trillion times per second
- 使用闭包实现点击按钮切换 toggle
- 基于三维GIS的不动产管理应用
- 浏览器tab页之间的通信
- Business visualization - make your flowchart'run'up
- 从MLPerf谈起:如何引领AI加速器的下一波浪潮
- 函数基本学习之一
猜你喜欢

Application of real estate management based on 3D GIS
Design and practice of new generation cloud native database

mysql 学习笔记-优化之SQL优化

从MLPerf谈起:如何引领AI加速器的下一波浪潮

"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
![[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial](/img/ac/655fd534ef7ab9d991d8fe1c884853.png)
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
![[deep learning] use deep learning to monitor your girlfriend's wechat chat?](/img/03/ecf50eacc91c0633b0d9689cdad2c2.png)
[deep learning] use deep learning to monitor your girlfriend's wechat chat?

PMP与NPDP之间的区别是什么?

K-means based user portrait clustering model

杰理之蓝牙耳机品控和生产技巧【篇】
随机推荐
业务可视化-让你的流程图'Run'起来
月入1W+的自媒体达人都会用到的运营工具
股票手机开户哪个app好,安全性较高的
Make a three digit number of all daffodils "recommended collection"
【MySQL】explain的基本使用以及各列的作用
Unity 使用Sqlite
burpsuite简单抓包教程[通俗易懂]
统计字符中每个字符出现的个数
What is the difference between consonants and Initials? (difference between initials and consonants)
打出三位数的所有水仙花数「建议收藏」
测试撤销1
企业架构与项目管理的关联和区别
String类型转换BigDecimal、Date类型
Training on the device with MIT | 256Kb memory
二叉树的基本操作
九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3
Aidl basic use
pytest合集(2)— pytest運行方式
AIDL基本使用
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖