http://127.0.0.1:3000/a.html
<iframe id="frame" src="http://127.0.0.1:3001/b.html"></iframe>
<script>
iframe.onload = function() {
iframe.contentWidnow.postMessage('msg from 3000/a.html', 'http://127.0.0.1:3001/')
}
// 监听b.html传来的信息
window.onmessage = function(e) {
console.log(e.data)
}
</script>
http://127.0.0.1:3001/b.html
<script>
// 监听b.html传来的信息
window.onmessage = function(e) {
console.log(e.data)
e.source.postMessage('send msg to 3000/a.html', e.origin)
}
</script>
标签:postMessage,function,http,0.1,html,3000,同源,页面
From: https://www.cnblogs.com/Lilc20201212/p/16667918.html