当前位置:网站首页>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 .
边栏推荐
- Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud
- LIS (longest ascending subsequence) problem that can be understood [easy to understand]
- 最近公共祖先(LCA)在线做法
- The difference between NiO and traditional IO
- 使用闭包实现点击按钮切换 toggle
- 物联网rfid等
- 面试题:MySQL的union all和union有什么区别、MySQL有哪几种join方式(阿里面试题)[通俗易懂]
- PMP与NPDP之间的区别是什么?
- PCB plug hole technology~
- [STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
猜你喜欢
随机推荐
mysql 学习笔记-优化之SQL优化
ICML2022 | 基于元语义正则化的介入性对比学习
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
Wechat applet, continuously playing multiple videos. Synthesize the appearance of a video and customize the video progress bar
Show member variables and methods in classes in idea
同花顺股票开户选哪个券商好手机开户是安全么?
What is the difference between consonants and Initials? (difference between initials and consonants)
基于YOLOv5的口罩佩戴检测方法
月入1W+的自媒体达人都会用到的运营工具
One of the basic learning of function
杰理之、产线装配环节【篇】
C中main函数的几种写法
分离字符串中的字母和数字并使得字母在前数组在后
杰理之、产线装配环节【篇】
[noip2013] building block competition [noip2018] road laying greed / difference
打出三位数的所有水仙花数「建议收藏」
Difference and use between require and import
Count the number of each character in the character
中通笔试题:翻转字符串,例如abcd打印出dcba
TOPS,处理器运算能力单位、每秒钟可进行一万亿次









