当有2个通道时,使用EasyXDM接口(用于跨域IFrame通信)方法调用远程方法两次

时间:2013-03-28 03:11:48

标签: easyxdm

我在主机页面上有2个IFrame,并希望在主机页面和IFrame之间设置双向通道。为此我使用了easyXDM接口类,并能够在主页和iFrame之间建立通信。

主机页面位于一个域中,所有IFrame位于不同的域中,但所有3个IFrame位于同一个域中。

我使用easyXDM接口类在主机页面上设置了2个通道,并指定了所需的属性,如本地方法,远程方法等。

主机页面有一个名为publish的本地方法,这个发布方法在所有IFrame上都是远程的。

我遇到的问题是,当从一个IFrame调用publish方法时,将在主机页面上调用所有IFrames通道的发布。

主机页面上的代码如下所示:

channel1 = new easyXDM.Interface(
    {
        local: "/name.html",
        remote: "PathToIFrame1.html",
        container: document.getElelmentById('Div1')
    }
    , {
        remote: {
            receive: {}
        },
        local: {
            publish: { method: function () { } }
        }
    }
    );

channel2 = new easyXDM.Interface(
    {
        local: "/name.html",
        remote: "PathToIFrame2.html",
        container: document.getElelmentById('Div2')
    }
    , {
        remote: {
            receive: {}
        },
        local: {
            publish: { method: function () { } }
        }
    }
    );

和IFrame方面的代码如下:

remote = new easyXDM.Interface({}, 
            {
            remote: {
                publish: {
                    isVoid: true
                }
            },
    local: {
        Receive: {
            isVoid: true,
            method: function (a, b) {                  

            }
        }            
    }

   });

}

当从IFrame端调用publish方法时,将调用channel1和channel2(在主机端)的发布方法。

有人可以建议这里可能出现的问题。

0 个答案:

没有答案