当前位置:网站首页>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 .
边栏推荐
- 选择在同花顺上炒股开户可以吗?安全吗?
- Unity 使用Sqlite
- 【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
- I received a letter from CTO inviting me to interview machine learning engineer
- 杰理之烧录上层版物料需要【篇】
- Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
- 【MySQL】explain的基本使用以及各列的作用
- 上半年暂停考试要补考?包含监理工程师、建筑师等十项考试
- Count the number of each character in the character
- 基于YOLOv5的口罩佩戴检测方法
猜你喜欢

指标陷阱:IT领导者易犯的七个KPI错误

Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan

杰理之、产线装配环节【篇】

九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3

企业架构与项目管理的关联和区别

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

Aidl basic use

Talking from mlperf: how to lead the next wave of AI accelerator

Classify boost libraries by function

Pytest Collection (2) - mode de fonctionnement pytest
随机推荐
MQ学习笔记
Make a three digit number of all daffodils "recommended collection"
[intelligent QBD risk assessment tool] Shanghai daoning brings you leanqbd introduction, trial and tutorial
AIDL基本使用
同花顺股票开户选哪个券商好手机开户是安全么?
股票手机开户哪个app好,安全性较高的
An operation tool used by we media professionals who earn 1w+ a month
MySQL learning notes - SQL optimization of optimization
杰理之、产线装配环节【篇】
[monomer] recommended configuration of streaming information i-bpsv3 server
Basic operation of binary tree
浏览器tab页之间的通信
一次调试去了解redis集群的slot机制
idea中类中显示成员变量和方法
PCB plug hole technology~
比较版本号[双指针截取自己想要的字串]
统计字符中每个字符出现的个数
Can I choose to open an account for stock trading on flush? Is it safe?
MySQL清空表数据
打出三位数的所有水仙花数「建议收藏」