前言在网上找了很多多标签页的数据通信案例。大体原理是可以使用postMessage实现跨域问题通信。最后,当前方法可以简单计时多个标签页的数据通信代码:一个页面JS部分functionreceiveMessage(event){if(event.origin!=="http://localhost:63343"){返回;}}window.addEventListener("消息",receiveMessage,false);functiontestOneWindowOpen(){varpopup=window.open('http://localhost:63343/javascript_top/ifreamtest/test2.html');console.log('开始执行');setTimeout(function(){console.log('执行定时任务开始');popup.postMessage("用户是'bob',密码是'secret'","http://localhost:63343/javascript_top/ireamtest/test2.html");console.log('执行定时器任务结束');},3000);console.log('执行结束');}functiontestTwoWindowOpen(){varpopup=window.open('http://localhost:63343/javascript_top/ireamtest/test3.html');console.log('开始执行');设置超时(功能(){控制台。log('执行定时任务开始');popup.postMessage("用户是'bob',密码是'secret'","http://localhost:63343/javascript_top/ireamtest/test3.html");console.log('执行定时任务结束');},3000);console.log('执行结束');}HTML部分
