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);

 

posted @ 2019-04-25 11:43  寂寞之砂  阅读(8554)  评论(0编辑  收藏  举报