Take the 2-minute tour ×

Is it possible to access an iframe from another iframe with JavaScript if these two iframes are embedded in the same parent and have the same origin but the parent is from another origin? If it is possible how do I do that?

share|improve this question
add comment

1 Answer

the iframe is a DOM element like any other, you can use document.getElementsByTagName("iframe")

share|improve this answer
To do that I need access to the parent with window.frameElement (or is there another way?). But the parent does not have the same origin as my iframes. –  Dmitry Jan 23 '13 at 8:45
do you have a link to the page in question? I don't see why you'd need to use the frameElement but then not knowing the page layout I cant say what your exact code would be. –  PrivateSniper Jan 23 '13 at 8:49
These 2 iframes are not inside each other. Those are on the same level, embedded on the same parent page. –  Dmitry Jan 23 '13 at 11:14
so on the parent page you can use document.getElementsByTagName("iframe")[0] for the first iframe or document.getElementsByTagName("iframe")[1] for the second iframe assuming these are the two only iframes on the page. –  PrivateSniper Jan 23 '13 at 12:48
add comment

Your Answer


