如何从JavaScript访问父Iframe [英] How to access parent Iframe from JavaScript

查看:95
本文介绍了如何从JavaScript访问父Iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我有一个IFrame,它调用相同的域页面。
我的问题是我想从这个被调用的页面(来自JavaScript)访问来自这个父iframe的一些信息。如何访问此iframe?

Well, I have an IFrame, which calls a same domain page. My problem is that I want to access some information from this parent Iframe from this called page (from JavaScript). How can I access this Iframe?

详细信息:有几个Iframe就像这样,可以加载相同的页面,因为我正在编写Windows环境。我打算关闭这个Iframe,这就是为什么我需要知道我应该从他内部关闭的原因。我有一个数组保持对这些Iframe的引用。

Details: There are several Iframes just like this one, that can have the same page loaded, because I am programming a Windows environment. I intend to close this Iframe, that's why I need to know which I should close from inside him. I have an array keeping references to these Iframes.

编辑:动态生成iframe

There iframes are generated dynamically

推荐答案

此外,您可以将名称和ID设置为相等的值

Also you can set name and ID to equal values

<iframe id="frame1" name="frame1" src="any.html"></iframe>

因此您可以使用子页面中的下一个代码

so you will be able to use next code inside child page

parent.document.getElementById(window.name);

这篇关于如何从JavaScript访问父Iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆