父级:
接收消息:
window.addEventListener('message', function(e){ console.log('父级接收消息------->',e) }, false);
发送消息:
<button @click="getInfo">发送消息</button>
info:{ message: "Hello Son!" }
getInfo(){ var sonIframe= document.getElementById("child"); sonIframe.contentWindow.postMessage(this.info, '*'); },
子级:
发送消息:
<button class="button qxDwBtn" οnclick="sendInfo('123')">发送消息</button>
function sendInfo(val){ window.parent.postMessage(val, '*'); }
接收消息:
window.addEventListener('message', function(e){ alert(e.data.message); }, false);