views:

38

answers:

1

I have a function in JavaScript which is included in the main HTML document and all embedded iframes. The function should operate in the main document. So I tried:

function f() {
    if (parent === null) {
        ...do the real work here...
    } else {
        parent.f(); // Call parent
    }
}

That doesn't work. Apparently, parent is never null or undefined. Currently, I use window == parent which works but I'm uneasy. Is that correct? Why? How compatible is this?

+2  A: 

May be window==top? Not tested with iframes, but I noticed that Google use that on gmail.

S.Mark
And I guess `top.f()` to call the topmost parent :-) Thanks, I completely missed `top`.
Aaron Digulla