Finding out inside which iframe a script is executing
Posted
by juandopazo
on Stack Overflow
See other posts from Stack Overflow
or by juandopazo
Published on 2010-05-02T22:37:42Z
Indexed on
2010/05/02
22:48 UTC
Read the original article
Hit count: 174
JavaScript
|dom
I have a page with several iframes. One of this iframes has a page from a different domain. Inside this iframe there's another iframe with a page from the parent domain.
my page from mydomain.com
-> an iframe
-> iframe "#foo" from another-domain.com>
-> iframe "#bar" from mydomain.com
-> another iframe
I need to get a reference to the "#foo" node inside the main page. The security model should allow me to do that because "#bar" has the same domain as the main page. So what I'm doing is iterating through the window.top
array and comparing each element to the window
object which is currently the "#bar" window object. My test code looks like:
for (var i = 0; i < top.length; i++) {
for (var j = 0; j < top[i].length; j++) {
if (top[i][j] == window) {
alert("The iframe number " + i + " contains me");
}
}
}
This works fine in all browsers, but Internet Explorer 6 throws a security error when accesing top[i][j]
. Any ideas on how to solve this on IE6?
Thanks!
© Stack Overflow or respective owner