本文翻译自:Redirect parent window from an iframe action
What JavaScript do I need to use to redirect a parent window from an iframe? 我需要使用什么JavaScript从iframe重定向父窗口?
I want them to click a hyperlink which, using JavaScript or any other method, would redirect the parent window to a new URL. 我希望他们单击超链接,该超链接将使用JavaScript或任何其他方法将父窗口重定向到新URL。
#1楼
参考:https://stackoom.com/question/2R3d/从iframe动作重定向父窗口
#2楼
这样可以解决苦难。
<script>parent.location='http://google.com';</script>
#3楼
尝试使用
window.parent.window.location.href = 'http://google.com'
#4楼
通过同一父项中的iframe重定向父项窗口中的iframe:
window.parent.document.getElementById("content").src = "content.aspx?id=12";
#5楼
window.top.location.href = 'index.html';
This will redirect the main window to the index page. 这会将主窗口重定向到索引页面。 Thanks 谢谢
#6楼
@MIP is right, but with newer versions of Safari, you will need to add sandbox attribute(HTML5) to give redirect access to the iFrame. @MIP是正确的,但是在Safari的较新版本中,您将需要添加沙箱属性(HTML5)以提供对iFrame的重定向访问。 There are a few specific values that can be added with a space between them. 可以添加一些特定的值,并在它们之间添加一个空格。
Reference(you will need to scroll): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe 参考(您需要滚动): https : //developer.mozilla.org/zh-CN/docs/Web/HTML/Element/iframe
Ex: 例如:
<iframe sandbox="allow-top-navigation" src="http://google.com/"></iframe>