0x01 背景
最近在做js开发的时候遇到了一个问题,找到解决方法后做一个总结。
用户登录php被嵌套在iframe中,登陆成功后需要浏览器跳转到首页,简单的使用window.location.href会让iframe层内部跳转,而父层却不会跳转。
0x02 解决方法
百度得到:
window.location.href
或location.href
===>本页面跳转
parent.location.href
==================>父页面跳转
top.location.href
====================>顶层(最外层)跳转
还可以在js中判断当前页面是否为最外层页面,从而实现最外层跳转的功能
- <script type="text/javascript">
- function breakout()
- {
- if (window.top!=window.self)
- {
- window.top.location="/example/hdom/tryjs_breakout.htm"
- }
- }
- </script>
0x03 参考链接
https://www.cnblogs.com/JemBai/archive/2011/10/09/2203429.html