子——>父
子级:
var mes={}
window.parent.postMessage(mes, ‘*’)
父级:
window.addEventListener(‘message’, (event) => {
const op = event.data
console.log(11,op)
})
父——>子
父:
window.οnscrοll=function(){
document.getElementById(‘container’).contentWindow.postMessage(document.documentElement.scrollTop || document.body.scrollTop, “*”)
}
子:
window.addEventListener(‘message’,function(event){
const op = event.data
console.log(11,op)
})