当数据来自其他域时,使用window.open将数据从父窗口发送到窗口弹出窗口

问题描述

我正在尝试使用这种方法将某些数据从父窗口发送到弹出窗口:

const mywindow = window.open(RE_SID_URL,"toolbar=no,location=no,status=no,menubar=0,resizable=1,left=400,width=500");
mywindow.myName = "myname". 

但是在弹出窗口中,它没有在窗口对象中设置,访问弹出窗口中的window.opener显示此错误: 异常:DOMException:阻止具有原始来源的框架访问跨域框架。在invokeGetter(:1:142)。 我在这里做错什么,任何帮助表示赞赏。我正在访问其他主机,但在弹出窗口中使用相同的域。

解决方法

当您遇到域问题并且想要交流时,发送消息。

/* the "Server" */

window.addEventListener("message",receiveMessage,false);

function receiveMessage(event) {

  // ... security check
  if (event.origin !== "http://example.org:8080")
    return;

  // ... process message
}

...

/* the "Client" */

targetWindow = window.opener;
// or targetWindow = HTMLIFrameElement.contentWindow;
// or targetWindow = window.open(RE_SID_URL,...)

targetWindow.postMessage("some message","*");
// or targetWindow.postMessage( {"data":2,"msg":"something"},"*");

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...