第一步:使用iframe侨接页面(开一个同源路由,使用iframe交互
)
iframe
子:window.parent.postMessage('data...', 'http://localhost:5173')
父: window.addEventListener('message', fn, false)
第二步: 使用同源storage通信方式
1、原页面
window.addEventListener('storage', (evt) => {
if (evt.key === ' .... 自定义storage - Key') {
console.log('更新一下')
}
})
2、新打开的tab页面
localStorage.setItem('....自定义storage - Key', Date.now())