javascript - How can I do cross-domain postMessage? -


the documentation postmessage implies cross-domain messaging possible. however:

// when popup has loaded, if not blocked popup blocker 

that isn't clear note of how it.

imagine 2 websites:

  1. [parent] hosted on qc-a.nfshost.com
  2. [child] hosted on qc-b.quadhome.com

in parent:

document.addeventlistener('message', function(e) {   alert('parent got (from ' + e.origin + '): ' + e.data);    e.source.postmessage('round-tripped!', 'http://qc-b.quadhome.com'); }, false);  function go() {   var w = window.open('http://qc-b.quadhome.com', 'test');    /* doesn't work because same-origin policy prevents knowing when      opened window ready. */    w.postmessage('vain attempt.', 'http://qc-b.quadhome.com'); } 

and, in child:

document.addeventlistener('message', function(e) {   alert('child got (from ' + e.origin + '): ' + e.data); }, false);  window.opener.postmessage('ready!', 'http://qc-a.nfshost.com'); 

all no avail.

help?

currently, seeing 2 issues. slight error in code , timeout issue.

1) error seeing in code you're using document.addeventlistener. think right 1 window.addeventlistener. in example on postmessage page.

2) timeout, can have child window postmessage parent. parent window know when child ready.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -