0


iframe之间的通信

iframe标签可以实现html主页面嵌套html子页面,那么父子页面间的传值是怎么进行的呢?
① 父页面监听iframe消息:

window.addEventListener('message', receiveMessageIframePage,false);

② 父页面发送给iframe页面的消息:

iframe.contentWindow.postMessage({type:'boundFileKeys',data:"消息内容体"},'*');

③ iframe页面监听父页面发过来的消息:

window.addEventListener('message', onMessage,false);

④ iframe页面给父页面发送消息:

window.parent.postMessage({type:'check',data:["自定义需要发送的数据"]},'*');
标签: 前端 html javascript

本文转载自: https://blog.csdn.net/m0_54399030/article/details/126657137
版权归原作者 可乐加冰^ 所有, 如有侵权,请联系我们删除。

“iframe之间的通信”的评论:

还没有评论