简体   繁体   English

来自 iframe 的父文档中的目标 DOM 节点

[英]Target DOM nodes in the parent document from an iframe

I have an iframe running code under an https protocol, the document containing the iframe is http.我在 https 协议下有一个 iframe 运行代码,包含 iframe 的文档为 Z80791B3AE7002FAA88C24687F It is not possible to change the protocol of either.无法更改其中任何一个的协议。 The problem is that when JS events happen in the iframe, DOM nodes in the parent should be manipulated.问题是当 iframe 发生 JS 事件时,应该操作父节点中的 DOM 节点。 Has anyone encountered a similar problem, and how did you solve it?有没有人遇到过类似的问题,你是怎么解决的?

If they're on the same domain, you should be able to access them via window.parent如果它们在同一个域上,您应该能够通过window.parent访问它们

Example, trigger a click示例,触发点击

window.parent.document.getElementById('ele_id').click();

Make sure your iframe is included with a protocol-less url.确保您的 iframe 包含在无协议 url 中。 For example:例如:

<iframe src="//www.google.com" width="400" height="300" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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