http://127.0.0.1:8888/A.html
<script>
$(function(){
const result = window.open('http://127.0.0.1:9999/B.html')
if (result) {
const param = {
type: 'customParam',
param: '123456'
}
setTimeout(() => {
result.postMessage(param, 'http://127.0.0.1:9999/B.html')
console.log('已发送')
}, 500)
}
})
<script>
http://127.0.0.1:9999/B.html
<script>
window.addEventListener('message', (e) => {
console.log(e.data) // 收到A.html发送的数据
console.log(e.origin)
console.log(e.source)
})
</script>