Redirect parent window from an iframe action

2018-12-31 19:51发布

What JavaScript do I need to use to redirect a parent window from an iframe?

I want them to click a hyperlink which, using JavaScript or any other method, would redirect the parent window to a new URL.

12条回答
萌妹纸的霸气范
2楼-- · 2018-12-31 20:31
window.top.location.href = "http://www.example.com"; 

As stated previously, will redirect the parent iframe.

查看更多
孤独寂梦人
3楼-- · 2018-12-31 20:31

or an alternative is the following (using document object)

parent.document.location.href = "http://example.com";
查看更多
无色无味的生活
4楼-- · 2018-12-31 20:33

Try using

window.parent.window.location.href = 'http://google.com'
查看更多
一个人的天荒地老
5楼-- · 2018-12-31 20:34

It is possible to redirect from an iframe, but not to get information from the parent.

查看更多
美炸的是我
6楼-- · 2018-12-31 20:35

Redirect iframe in parent window by iframe in the same parent:

window.parent.document.getElementById("content").src = "content.aspx?id=12";
查看更多
春风洒进眼中
7楼-- · 2018-12-31 20:37
window.top.location.href = 'index.html';

This will redirect the main window to the index page. Thanks

查看更多
登录 后发表回答