iframe嵌套层的父级跳转问题

/ 0评 / 0

0x01 背景

最近在做js开发的时候遇到了一个问题,找到解决方法后做一个总结。

用户登录php被嵌套在iframe中,登陆成功后需要浏览器跳转到首页,简单的使用window.location.href会让iframe层内部跳转,而父层却不会跳转。

0x02 解决方法

百度得到:

window.location.hreflocation.href===>本页面跳转

parent.location.href==================>父页面跳转

top.location.href ====================>顶层(最外层)跳转

还可以在js中判断当前页面是否为最外层页面,从而实现最外层跳转的功能

  1. <script type="text/javascript">  
  2. function breakout()   
  3. {   
  4.   if (window.top!=window.self)    
  5.     {   
  6.     window.top.location="/example/hdom/tryjs_breakout.htm"  
  7.     }   
  8. }   
  9. </script>

0x03 参考链接

https://www.cnblogs.com/JemBai/archive/2011/10/09/2203429.html

https://www.cnblogs.com/lxf1117/p/3702839.html

https://www.cnblogs.com/xiaohuasan/p/5329510.html

发表回复

您的电子邮箱地址不会被公开。