0

I saw this question on redirection iFrames Redirect parent window from an iframe action but the answer addressed redirecting the entire page.

The redirect was using:

window.top.location.href = "http://www.example.com"; 

Is there a way to redirect nested iFrames?

ie.

<browser>
    <iframe src="someSrc">
        <!--iFrame page-->
        <iframe src="nestedSrc"></iframe>
    </iframe>
</browser>

So from the nestedSrc redirect someSrc to another page instead of redirecting the browser page.

Community
  • 1
  • 1
Adjit
  • 10,134
  • 12
  • 53
  • 98

1 Answers1

0

If you have access to the parent iframe's domain, you can simply redirect it using:

window.parent.location = 'http://new.location.com';

Small parent/top example

<Browser>
    <iframe1>
        <iframe2>
        </iframe2>
    </iframe1>
</Browser>

Inside iframe2 the following are true:

window.parent.parent == window.top // true
window.parent == window.top.frames[0] // true

Note: the following example presumes browser and iframe 1 & 2 all are from the same domain

Matyas
  • 13,473
  • 3
  • 60
  • 73
  • I know about the domain issues, but I do know that for redirecting the browser from an `iFrame` is allowed to be cross domain, is the same true for redirecting a parent iFrame? – Adjit Mar 10 '15 at 15:59
  • Yes, the cross domain communication is blocked also between two `iframe`s not only an `iframe` and `browser` (`window.top`) – Matyas Mar 10 '15 at 16:09