0

I have a form inside of an iframe. When I click a button on the form, I want the content of the outer containing page (NOT the content of the iframe) to be replace with the specified url.

If the form were not inside of an iframe this works ...

<input type='button' name='Next' value='Next Page'
onclick='window.location.replace("http://www.facebook.com");' />

The same code, inside of an iframe, replaces only the content of the iframe, not the content of the entire containing page.

How do I do it from inside of an iframe?

4

2 回答 2

0

使用 top 访问父级:

top.location = "http://www.example.com"
于 2013-05-02T00:15:20.220 回答
0
window.top.location.href = "http://www.site.com";

如前所述,将重定向父 iframe。要记住的一件事是,网站和 iframe 中包含的网站都需要在同一个域中才能正常工作,否则您将收到拒绝访问异常。

因此,如果网站是“www.site.com”,而 iframe 是“iframe.site.com”,则您需要在两个页面中输入:

document.domain = "site.com"

如此处所见

于 2013-05-02T00:16:38.350 回答