How to Ask the Parent to Refresh Its Page From a Child Page Using EasyXDM Messaging Provider to Consumer Approach?

201 views
Skip to first unread message

David Wu

unread,
Jan 15, 2015, 10:59:17 AM1/15/15
to eas...@googlegroups.com
Hi,
I have the following scenario:

A .NET aps page (www.mydotnet.com/easyXDM.asp) that opens a new page in a separate domain (www.mychild.com/viewer). When the viewer page (in jsp) saves its data, the viewer (child) is required to send a message telling the parent page to refresh, in this case, it is the .NET asp page. Both pages are rendered or displayed in IE7 browser.

Since this a typical cross domain problem, I finally found the easyXDM framework to tackle this problem. So I have the following eashXDM scripted:

In the parent, I have this:

    <script type="text/javascript" src="Scripts/easyXDM.js"></script>
    <script type="text/javascript" src="Scripts/json2.js"></script>
    <script type="text/javascript">
        //parent
        var socket = new easyXDM.Socket({
            local: "name.html",
            swf: "easyxdm.swf",
            onMessage: function (message, origin) {
                alert("This is a message: " + message + ". received from " + location);
                window.location.reload();
            }
        });

    </script>

In the child, I have this:

<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/easyXDM.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/json2.js"></script>
<script type="text/javascript">
 var socket = new easyXDM.Socket({
   local: "name.html",
            swf: "easyxdm.swf",
   onMessage: function(message, origin){
       alert("Received '" + message + "' from '" + origin + "'");
   },
 });

function sendMessageToParent() {
socket.postMessage("You need to refresh.");
};
</script>
.....
<body>
<form id="myform" name="myform" onsubmit="return sendMessageToParent();">
<label for="send_message"></label>
<input type="text" name="message" placeholder="Type your message here" id="message" />
<input type="submit" name="btn_submit" value="Send" id="btn_submit">
</form>
</body>
.....

The result was, communication between the two domain seemed to be working. However, when invoking the parent page to refresh, an action was triggered by sending the message to the parent domain, everything seemed to be happening on the child page side, such as the alert popup (from both parent and child pages), the page refresh, etc. Again, everything was taking place on the child page side, like all the actions, for some reasons, which I don't understand.

Did I configure the easyXDM socket correctly for both sides?

Please help!

Thanks,
DCWu

Øyvind Sean Kinsey

unread,
Jan 15, 2015, 9:55:38 PM1/15/15
to easyxdm
You have them configured the wrong way around - the parent should be setting remote, and should probably also be setting a container if the intention is for this iframe to be visible.

Right now I'm guessing you have an iframe in your parent which is loading the child, which in turn is loading the first page.

--
You received this message because you are subscribed to the Google Groups "easyxdm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to easyxdm+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages