如何使用 jQuery 公开 IFrame 的 DOM? [英] How to expose IFrame's DOM using jQuery?

查看:25
本文介绍了如何使用 jQuery 公开 IFrame 的 DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代表特定 IFrame 的原型.该原型有一个名为 GoToUrl(...) 的函数,用于在 IFrame 中打开给定的 url.

I have a prototype representing a particual IFrame. That prototype have a function called GoToUrl(...) that opens the given url within the IFrame.

我的问题是:如何创建InternalDOM"属性并使该属性引用内部 IFrame 的窗口"对象(根 DOM 对象)?以这样的方式:如果我的 IFrame 公开了一个页面,该页面在它的窗口"对象中有一个对象 X,我可以这样做:

My question is: How do I create an "InternalDOM" property and make this property refer to the "window" object (the root DOM object) of the IFrame inside? In such way that: If my IFrame exposes a page which has an object X in it's "window" object I could do:

MyFrameObject.GoToUrl(pageXurl);
MyFrameObject.InternalDOM.X

任何帮助将不胜感激.

PS:我会接受不一定与 jQuery 相关的答案,但我更喜欢 jQuery 解决方案.

PS: I would accept answers not necessarily related to jQuery but I would prefer a jQuery solution.

推荐答案

要获取框架的 window 对象,您可以使用 window.frames 数组:

To get the window object for a frame you can use the window.frames array:

var iframewindow= frames['iframe_name'];

这要求你给