【问题标题】:window.open postmessage or pass data to parent window cross domainwindow.open postmessage 或传递数据到父窗口跨域
【发布时间】:2021-02-17 07:07:10
【问题描述】:

我正在使用 window.open 打开一个域与父窗口不同的 url

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

原始域不同 abc.com 它不是子域现在我在弹出窗口上打开一个表单,我希望在弹出窗口上提交表单时,另一个域上的原始窗口应该刷新或重定向到我正在尝试的另一个页面 window.postmessage

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

在弹出窗口中

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

但它现在可以工作 window.top 或 window.parent 现在也可以工作。 当我尝试在弹出窗口中使用 window.opener 时收到跨源警告。

【问题讨论】:

    标签: javascript redirect iframe popup cross-domain


    【解决方案1】:

    使用对弹出窗口的引用尝试在父窗口上

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-15
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多