gpt4 book ai didi

javascript - var myvalue = window.opener.document.getElementById (“parentId1” ) 不工作

转载 作者:行者123 更新时间:2023-11-30 10:21:58 26 4
gpt4 key购买 nike

我试图使用

从我的 child.jsp 获取值到我的 parent.jsp
var myvalue = window.opener.document.getElementById(“parentId1”) 

即使在控制台中未发现任何错误,该值也未进入父页面。

子弹出窗口的 url 以 https://host.example.com:7001/..... 开头,父页面的 url 以 http 开头://anotherhost:8080/webapp....在与另一台服务器上的子窗口和父页面通信时是否存在任何问题?

如果是,我该如何解决这个问题?

最佳答案

...is there any issue in communicating with a child window and a parent page which is on another server?

是的,这被浏览器实现的 Same Origin Policy 阻止了。 .

如果您控制两个服务器,请考虑使用 Cross Origin Resource Sharing .

或者,如果您控制页面上的 JavaScript 代码而不是服务器(或者如果您更喜欢这种机制),您可以使用 postMessage 将消息从一个窗口发送到另一个窗口。您不能像在代码片段中那样直接访问另一个窗口的元素,但是这两个页面可以合作将相关值从一个页面传递到另一个页面,甚至是跨域。关于 postMessage 的更多信息:MDN | Spec

除非您可以使用 CORS 或 postMessage,否则我认为您不能在客户端进行;你需要一个代理。

关于javascript - var myvalue = window.opener.document.getElementById (“parentId1” ) 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21157927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com