Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
168 views
in Technique[技术] by (71.8m points)

javascript - 如何从JavaScript访问父iframe(How to access parent Iframe from JavaScript)

Well, I have an IFrame, which calls a same domain page.

(好吧,我有一个IFrame,它调用相同的域页面。)

My problem is that I want to access some information from this parent Iframe from this called page (from JavaScript).

(我的问题是我想从这个被调用的页面(通过JavaScript)访问该父iframe的某些信息。)

How can I access this 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.

(详细信息:由于我正在对Windows环境进行编程,因此有几个这样的iframe可以加载相同的页面。)

I intend to close this Iframe, that's why I need to know which I should close from inside him.

(我打算关闭此iframe,这就是为什么我需要知道应该从他内部关闭哪个框架。)

I have an array keeping references to these Iframes.

(我有一个数组,保留对这些iframe的引用。)

EDIT: There iframes are generated dynamically

(编辑:有iframe是动态生成的)

  ask by José Leal translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Also you can set name and ID to equal values

(您也可以将名称和ID设置为相等的值)

<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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...