js iframe传参
作者:互联网
父级向iframe内部发送
const mapFrame = this.$refs.iframeref;
//处理兼容
if (mapFrame.attachEvent) {
mapFrame.attachEvent('onload', function() {
const iframeWin = mapFrame.contentWindow
iframeWin.postMessage(data, '*')
})
} else {
mapFrame.onload = function() {
const iframeWin = mapFrame.contentWindow
iframeWin.postMessage(data, '*')
}
}
iframe内部接收
window.addEventListener('message', (event) => {
let form = event.data
checkform(form)
}, false);
iframe内部向父级发送
window.parent.postMessage({
abc: '123456',
}, '*');
父级接收
window.addEventListener('message', (event) => {
console.log(event.data)
}, false)
标签:传参,父级,js,iframeWin,mapFrame,iframe,data,event 来源: https://www.cnblogs.com/anans/p/16421672.html