当前位置:网站首页>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 .
边栏推荐
- AIDL基本使用
- PHP reflective XSS, reflective XSS test and repair
- 【MySQL】索引的创建、查看和删除
- Four methods of JS array splicing [easy to understand]
- [STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
- 首席信息官对高绩效IT团队定义的探讨和分析
- A debugging to understand the slot mechanism of redis cluster
- matlab遍历图像、字符串数组等基本操作
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
- String type conversion BigDecimal, date type
猜你喜欢

100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖

基于YOLOv5的口罩佩戴检测方法

News classification based on LSTM model

收到一封CTO来信,邀约面试机器学习工程师

手动实现function isInstanceOf(child,Parent)

Do you want to make up for the suspended examination in the first half of the year? Including ten examinations for supervision engineers, architects, etc

Go - exe corresponding to related dependency

I received a letter from CTO inviting me to interview machine learning engineer
![[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?

工控设备安全加密的意义和措施
随机推荐
Spark面试题
Can I choose to open an account for stock trading on flush? Is it safe?
Four methods of JS array splicing [easy to understand]
中通笔试题:翻转字符串,例如abcd打印出dcba
4. 对象映射 - Mapping.Mapstercover
An operation tool used by we media professionals who earn 1w+ a month
MySQL empties table data
业务可视化-让你的流程图'Run'起来
上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
二叉树的基本操作
焱融看 | 混合云时代下,如何制定多云策略
MIT|256KB 内存下的设备上训练
Pytest collection (2) - pytest operation mode
选择在同花顺上炒股开户可以吗?安全吗?
旁路由设置的正确方式
PHP reflective XSS, reflective XSS test and repair
基于YOLOv5的口罩佩戴检测方法
【深度学习】利用深度学习监控女朋友的微信聊天?
从MLPerf谈起:如何引领AI加速器的下一波浪潮
MySQL learning notes - SQL optimization of optimization