Easy XDM - IFrame 导航中断套接字

Easy XDM - IFrame Navigation Breaks Socket

我正在使用 EasyXDM 来处理 cross-domain 通信,以便 parent 知道 child 的大小和 child 的位置。我已经开始调整尺寸了。问题是当我在 iframe 中导航时,我想将该位置推回到 parent。

问题是,当我更改页面时,套接字无法再次创建,给我 VM87 Core.js:324 未捕获错误:url 未定义或为空.

还有其他人 运行 参与其中吗?

Parent(消费者):

<script language="javascript">
    (function () {
    // CTOR has side effect of creating globals for socket
        var socket = new easyXDM.Socket({
            remote: "@(Model.Url)" + document.location.hash,
            container: $("#pluginFrame")[0],
            onMessage: function (message, origin) {
                var messageAsObject = JSON.parse(message);

                if (messageAsObject.height) {
                    $("#pluginFrame iframe").height(messageAsObject.height);
                }

                if (messageAsObject.path) {
                    document.location.hash = messageAsObject.path;
                }
            },
            onReady: function() {
                console.log("Shell Socket Ready");
                $("#pluginFrame iframe").width("100%");
            }
        });
    })();
</script>

Child(制作人)Razor Layout

<script language="javascript">
    (function () {
        debugger;
        var socket = new easyXDM.Socket({
            onReady: function () {
                console.log("eBox Ready");

                socket.postMessage(JSON.stringify({
                    height: $(".body-content").outerHeight(),
                    path: document.location.pathname
                }));
            }
        });

        $("body-content")
            .on("change",
                function () {
                    socket.postMessage(JSON.stringify({
                        height: $(".body-content").outerHeight()
                    }));
                });

        $(document.location.pathname)
            .on("change",
                function () {
                    socket.postMessage(JSON.stringify({
                        path: document.location.pathname
                    }));
                });

        socket.postMessage(JSON.stringify({
            path: document.location.pathname
        }));
    })();
</script>

从我所看到的一切来看,没有任何可能的方法来做我想做的事情。似乎我最终试图解决的问题的唯一解决方案是使用此处提到的双 iframe 方法,将路由推入父级的位置哈希。

Resizing an iframe based on content