父iframe元素的访问容器(iframe内的iframe) [英] Access container of parent iframe element (Iframe inside iframe)
本文介绍了父iframe元素的访问容器(iframe内的iframe)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有下一个元素结构:
I have next structure of elements:
<div class="container">
<iframe class="outer">
..
<iframe class="inner">
actual markup with scripts here
</iframe>
</iframe>
</div>
使用纯JavaScript,我已经指出要从内部 iframe转到外部iframe:
using pure javascript, i've meneged to get out of "inner" iframe into outer one:
//this is HTML tag of ".outer" iframe
var parent = window.parent.document.getElementsByTagName('html')[0];
但我仍然需要获取 .container元素才能对其进行操作。
谁能告诉我如何从 .inner元素内的脚本中获取 .container元素吗?
but still i need to get to ".container" element in order to manipulate it. Can anyone tell me how to get ".container" element from script inside ".inner" element??
推荐答案
也许是这样:
var outer = window.parent;
var mainWindow = outer.parent;
var container = mainWindow.document.getElementsByClassName('container')[0];
但请不要忘记您的iframe必须位于同一域中。
but dont forget that your iframes have to be on the same domain.
这篇关于父iframe元素的访问容器(iframe内的iframe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文