I am passing a message between 2 domains, number 1 is www.domain1.com/stuff and number 2 is www.domain1.com:8888/stuff/ (Its a python rest API) I am sending data from 1 to 2 using the following code which is perfect and works...
var popup = window.open(imgtarget, 'myWindow','left=20,top=20,width=500,height=800,toolbar=1,resizable=0');
setTimeout(function(){
popup.postMessage(domain,imgtarget);
}, 1000);
The no 2 domain/ window code receives the code perfectly using this code and it even sucsessfully sends back the "yo yo yo" message to number 1 window using the following code...
window.addEventListener('message',function(event) {
if(event.origin !== 'http://www.domain1.com') return;
domain =event.data,event;
origin_site=event.origin ;
event.source.postMessage('Yo yo yo',event.origin);
},false);
then I take that message from number 1 and send it to the databse which returns another value to me which I am trying to send back to number 1 and the code goes like this which is in a completely different function a few seconds later...
postMessage("Messageforwindow1","www.domain1.com/stuff");
But it gives me this error message...
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://www.domain1.com/) does not match the recipient window's origin ('http://www.domain1.com:8888').
AS I said I can return the message in the addEventListener but not later. Any ideas how to get around this or if you know what the heck Im going on about? Please help if you can. Thanks