javascript window.opener.document.getElementById("parentId1").value = myvalue 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18351446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:35:40  来源:igfitidea点击:

window.opener.document.getElementById("parentId1").value = myvalue not working

javascriptsecurityhttphttps

提问by being_uncertain

I was trying to get the value from my child.jsp to my parent.jsp using window.opener.document.getElementById("parentId1").value = myvalue;

我试图使用从我的 child.jsp 到我的 parent.jsp 的值 window.opener.document.getElementById("parentId1").value = myvalue;

Even though there were no errors found in the console the value is not getting in the parent page.

即使在控制台中没有发现错误,值也没有进入父页面。

The child popup window has the url starting like, https://safe.cresecure.net/securepayments.....and the parent page urlstarts with http://....is there any issue in communicating with a secure child window and a parent page which is not secure?

子弹出窗口的 url 以 like 开头, https://safe.cresecure.net/securepayments.....父页面url开头http://....为与安全子窗口和不安全的父页面通信是否有任何问题?

If so how can I solve this issue?

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

回答by bobince

is there any issue in communicating with a secure child window and a parent page which is not secure?

与安全的子窗口和不安全的父页面进行通信是否有任何问题?

Yes. HTTP and HTTPS make for separate script origins. (If they were not separate origins then an unprotected page could script into an HTTPS page and change all its content, defeating the purpose of HTTPS.)

是的。HTTP 和 HTTPS 用于单独的脚本来源。(如果它们不是单独的源,则未受保护的页面可以将脚本写入 HTTPS 页面并更改其所有内容,从而违背 HTTPS 的目的。)

If so how can I solve this issue?

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

  1. Same origin. Serve the parent page through HTTPS, and either put them on the same hostname or set document.domainto a shared parent domain on both documents.

  2. Cross-origin messaging. window.postMessage; if you need to support older browsers(primarily IE<8) then there are horrible backwards compatibility hacks (like communicating through document.cookieor hash navigation).

  3. Server interaction. One document sends the information to the server and the server shares it back with the other document (eg using XMLHttpRequest).

  1. 相同的起源。通过 HTTPS 为父页面提供服务,并将它们放在相同的主机名上或document.domain在两个文档上设置为共享父域。

  2. 跨域消息传递。window.postMessage; 如果您需要支持较旧的浏览器(主要是 IE<8),那么有可怕的向后兼容性黑客(例如通过通信document.cookie或哈希导航)。

  3. 服务器交互。一个文档将信息发送到服务器,服务器将其与另一个文档共享回来(例如,使用 XMLHttpRequest)。