Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cross Domain sending between child window and iframe

Status
Not open for further replies.

basil3legs

Programmer
Jun 13, 2002
157
GB
Hi,

I have created some javascript that reads data from a web page, creates an iframe with a form in it which autosubmits to a php page on another domain. This then returns some information to the original page using javascript's postMessage with an EventListener on the original page. This is all working fine.

However, I now want the original web page opened automatically by another one (on the same domain as it is) using mywindow = window.open(OriginalURL); The form still runs fine and data is submitted to the cross domain php page but I now can't get any data back from it to either of the pages (either would do as I can easily send the data back from the parent to the child).

I have also tried moving the EventListener around in the code to ensure the child page is fully loaded before it is added.

Any help would be greatly appreciated.

By the way, this is to run in Opera mainly - I really don't mind if it doesn't work in IE!

The original code (that worked before making it a child) was:

Code:
On php page:

echo '<script type="text/javascript">';
echo 'top.postMessage ("' . $strtosend . '", "[URL unfurl="true"]http://www.somedomain.com")';[/URL]
echo '</script>';


In Javascript on original page:


window.addEventListener( "message",
          function (e) {
                if(e.origin !== '[URL unfurl="true"]http://www.anotherdomain.com'){[/URL] return; } 
                somefunction(e.data);
          },
          false);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top