简体   繁体   English

从嵌套iFrame重定向父iFrame

[英]Redirect parent iFrame from nested iFrame

I saw this question on redirection iFrames Redirect parent window from an iframe action but the answer addressed redirecting the entire page. 从iframe动作中看到了有关重定向iFrames 重定向父窗口的问题,但解决了重定向整个页面的问题。

The redirect was using: 重定向使用的是:

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

Is there a way to redirect nested iFrames? 有没有办法重定向嵌套的iFrame?

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. 因此,从nestedSrc重定向someSrc到另一个页面,而不是重定向浏览器页面。

If you have access to the parent iframe's domain, you can simply redirect it using: 如果您有权访问父iframe的域,则可以使用以下方法简单地将其重定向:

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

Small parent / top example parent / top例子

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

Inside iframe2 the following are true: 在iframe2中,以下是正确的:

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 注意:以下示例假定browseriframe 12都来自同一域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM