从iframe操作redirect父窗口
我需要使用哪些JavaScript来从iframeredirect父窗口?
我希望他们点击超链接,使用JavaScript或任何其他方法,将父窗口redirect到一个新的URL。
 window.top.location.href = "http://www.example.com"; 
如前所述,将redirect父级iframe。
 我发现<a href="..." target="_top">link</a>适用 
 window.top.location.href = "http://example.com"; 
  window.top指的是框架层次结构顶部页面的窗口对象。 
或者一个替代scheme如下(使用文档对象)
 parent.document.location.href = "http://example.com"; 
  target="_parent"对我很好。 容易和无忧无虑! 
@MIP是正确的,但有了更新版本的Safari,您将需要添加sandbox属性(HTML5)以redirect访问iFrame。 有几个具体的值可以添加与他们之间的空间。
参考(您将需要滚动): https : //developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
例如:
 <iframe sandbox="allow-top-navigation" src="http://google.com/"></iframe> 
 window.top.location.href = 'index.html'; 
这会将主窗口redirect到索引页面。 谢谢
可以从iframeredirect,但不能从父级获取信息。
这将解决苦难。
 <script>parent.location='http://google.com';</script> 
尝试使用
 window.parent.window.location.href = 'http://google.com' 
如果您想要redirect到另一个域,而用户不必执行任何操作,则可以使用该属性的链接:
 target="_parent" 
如前所述,然后使用:
 document.getElementById('link').click(); 
让它自动redirect。
例:
 <!DOCTYPE HTML> <html> <head> </head> <body> <a id="link" target="_parent" href="outsideDomain.html"></a> <script type="text/javascript"> document.getElementById('link').click(); </script> </body> </html> 
注意:javascript声明()命令必须在声明链接后出现。
在同一个父代中通过iframe在父窗口中redirectiframe:
 window.parent.document.getElementById("content").src = "content.aspx?id=12";