如何利用js在两个html窗口间通信
网络编程 2021-07-04 14:07www.168986.cn编程入门
这篇文章主要介绍了如何利用js在两个html窗口间通信,如果读者们有类似的需求,可以参考下
场景:当A页面打开B页面,在B页面操作后,A页面需要同步变更数据时
A 页面 ,http://127.0.0.1:10001/A.html
var domain = 'http://127.0.0.1:10001'; window.open('http://127.0.0.1:10001/B.html'); window.addEventListener('message', function (event) { if (event.origin !== domain) return; console.log('message received: ' + event.data, event); }, false);
B 页面 ,http://127.0.0.1:10001/B.html,opener是当前窗口的打开者引用
var domain = 'http://127.0.0.1:10001'; window.opener.postMessage("suess", domain); window.close();
如果是需要A打开B的同时向B中发送数据时
// 发送数据方 var domain = 'http://127.0.0.1:10001'; var myPopup = window.open('http://127.0.0.1:10001/B.html'); myPopup.postMessage('数据', domain); // 接收数据方 window.addEventListener('message', function(event) { if(event.origin !== 'http://127.0.0.1:10001') return; console.log('message received: ' + event.data,event); },false);
以上就是如何利用js在两个html窗口间通信的详细内容,更多关于js在两个html窗口间通信的资料请关注狼蚁SEO其它相关文章!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程