当前位置:网站首页>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 .
边栏推荐
- 一次调试去了解redis集群的slot机制
- 物联网rfid等
- js如何获取集合对象中某元素列表
- Can I choose to open an account for stock trading on flush? Is it safe?
- Use of vscode
- News classification based on LSTM model
- Microsoft, Columbia University | Godel: large scale pre training of goal oriented dialogue
- idea中类中显示成员变量和方法
- MQ learning notes
- Aidl basic use
猜你喜欢
随机推荐
焱融看 | 混合云时代下,如何制定多云策略
Burpsuite simple packet capturing tutorial [easy to understand]
Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
"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
Difference and use between require and import
I received a letter from CTO inviting me to interview machine learning engineer
【单体】流辰信息I-BPSv3服务器推荐配置
游览器打开摄像头案例
Unity 使用Sqlite
js数组拼接的四种方法[通俗易懂]
ICML2022 | 基于元语义正则化的介入性对比学习
上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
Test cancellation 1
GCC编译
Pytest collection (2) - pytest operation mode
CNN卷积神经网络原理讲解+图片识别应用(附源码)[通俗易懂]
统计字符中每个字符出现的个数
[monomer] recommended configuration of streaming information i-bpsv3 server
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
Aidl basic use








