一:a页面
1:打开b页面
let isB= window.open('b.html','b');

2:a页面发送消息给b页面
    isB.postMessage("dsddfsdf", 'b.html');
 
 
  二: b页面
 
       b页面接受a页面的消息
 
 
window.onload = function() {
window.addEventListener('message', function(event) {
 //可以通过event.origin  判断消息来源
 
console.log(event.data,'a发送来的消息');
//作为接受到消息的回应 同样给a页面发送一个消息
   
 
//如果a页面没有关闭
 if(window.opener){
     window.opener.postMessage('我是b,我收到消息了','a.html');
}else{
console.log("a页面关闭了啊");
}
 
});
}
 
 
LAST:
 
在a页面同样添加 接受消息的事件  接受b接受消息的反馈信息
window.onload = function() {
window.addEventListener('message', function(event) {
//其他操作
})
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-07-07
  • 2021-08-01
  • 2021-06-03
  • 2022-12-23
相关资源
相似解决方案