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

查看:22
本文介绍了如何从 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

推荐答案

你也可以将 name 和 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天全站免登陆