假设A和B两个页面,处于两个不同的域中,现在在A页面中,通过iframe方式引入了B页面,那么B页面中的参数如何传递给A页面呢?A页面中又如何获取B页面传递过来的数据呢?
A页面内容
<iframe id="iframe-a" width="100px" height="100px" src="B页面地址,可以带参数" frameborder="0" sandbox="allow-modals allow-forms allow-scripts allow-same-origin allow-popups" allowtransparency="true"></iframe>
//监听B页面中的message事件
if (typeof window.addEventListener != "undefined") {
window.addEventListener("message", iframeFunCb, false);
} else if (typeof window.attachEvent != 'undefined') {
//兼容不支持addEventLinstener的IE。
window.attachEvent("onmessage", iframeFunCb);
}
// 子页面事件回调,在该回调函数中,可以获取B页面传递过来的参数
function i