What's the topmost iframe in the same domain?

Posted by Jakob Stoeck on Stack Overflow See other posts from Stack Overflow or by Jakob Stoeck
Published on 2010-05-21T19:09:25Z Indexed on 2010/05/21 19:10 UTC
Read the original article Hit count: 296

Filed under:

How can I get the topmost iframe which is in the same domain, i.e.

iframe level 1 example.org
    iframe level 2 example.org
    iframe level 2 example.org 
        iframe level 3 example.org <-- would give me iframe level 1

iframe level 1 other-example.org
    iframe level 2 example.org
    iframe level 2 example.org 
        iframe level 3 example.org <-- would give me iframe level 2

iframe level 1 other-example.org
    iframe level 2 example.org
    iframe level 2 example.org <-- would give me iframe level 2 (this)

I need it because I have a website which should work in an iframe of another domain and stand-alone.

In this website there are scripts which depend on window.top which shouldn't be top but the topmost iframe in the same domain.

© Stack Overflow or respective owner

Related posts about JavaScript