简体   繁体   中英

window.open postmessage or pass data to parent window cross domain

I Am using window.open to open a url with different domain than the parent window

url = "xyz.com/?"+form_data+"&first_page=1";
       newwindow=window.open(url,'name','height=350,width=800,top=250, left=600');

The orignal domain is different abc.com it is not a subdomain Now I am opening a form on the popup window and I wannt when ever I Submit the form on the popup window the the original window which is on the other domain should refresh or redirect to another page I am trying window.postmessage

window.opener.postMessage("message",'*');

on the popup window

 setInterval(function(){
 document.addEventListener('message', function(e) {
 alert('got (from ' + e.origin + '): ' + e.data);
 }, false);
 },1000);

but it is now working window.top or window.parent is now working as well. I get cross origin warning when I try to use the window.opener in the popup.

Try onn the parent window using the reference to the popup

newwindow=window.open(url,'name','height=350,width=800,top=250, left=600');
newwindow.postMessage('message','*')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM