iframe之间的postMessage传参

时间:2023-03-09 04:33:36
iframe之间的postMessage传参

1、传参

    function IframeClose() {
var obj = {method: "iframeClose"};
window.parent.postMessage(obj, "*");
} //删除
function deleteExercise(exeid) {
//删除习题:delExercise(习题id)
var obj = {method: "deleteExercise", exeid: exeid};
window.frames[0].postMessage(obj, domain);
}

2、接参

    window.addEventListener('message', function (e) {
if (e.data.method == "iframeClose") {
Modal.Close("#ExerciseScoreIframe");
if (typeof iframecallback == "function") {
iframecallback();
} else {
window.location.reload();
}
}
}, false); window.addEventListener('message', function (e) {
if (e.data.removeLayout != undefined && e.data.removeLayout == "success") {
console.log("删除排版成功");
window.location.reload();
}
}, false);