admin管理员组文章数量:1332404
I have next structure of elements:
<div class="container">
<iframe class="outer">
..
<iframe class="inner">
actual markup with scripts here
</iframe>
</iframe>
</div>
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];
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??
I have next structure of elements:
<div class="container">
<iframe class="outer">
..
<iframe class="inner">
actual markup with scripts here
</iframe>
</iframe>
</div>
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];
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??
Share Improve this question asked Feb 14, 2014 at 13:12 KamiliusKamilius 58716 silver badges34 bronze badges2 Answers
Reset to default 7Maybe this:
var outer = window.parent;
var mainWindow = outer.parent;
var container = mainWindow.document.getElementsByClassName('container')[0];
but dont forget that your iframes have to be on the same domain.
I would try
var containerElement = window.frames.top.top.document.getElementsByClassName('container')[0];
But be careful: If you try to break out of your frame and want to access a document with a different domain, ports or protocol, your browser (hopefully) will return an exception like this:
Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
本文标签: javascriptAccess container of parent iframe element (Iframe inside iframe)Stack Overflow
版权声明:本文标题:javascript - Access container of parent iframe element (Iframe inside iframe) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742277567a2445484.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论