postMessage使用方法

一、子頁面向父頁面發送消息
var parentData = {type: 'passDataBack', data: passData};
window.parent.postMessage(parentData, '*');

二、父頁面向子頁面發送消息
var data = {type: 'answerResult', data: jsonData.data};
$(".courseware_h5 iframe")[0].contentWindow.postMessage(data, '*');

三、接收消息方法
window.addEventListener('message', function (e) {
})
相關文章
相關標籤/搜索