背景:
后台操作,有时候session过期刚好打开layui弹出框,于是重定向登录页面就显示在弹出框中了。
如下图:
解决办法有两个:
1:跳转登录界面
在登陆界面写入如下js:
$(function(){
if (top != window){
top.location.href = window.location.href;
}
})
这样当登陆页面不是显示在window窗口时,顶级页面(父级页面?不知道这么说对不对)就会跳转到登录页面,也就是浏览器当前页面(弹出层的父集页面)会直接跳转到登录页面。
2:当前小窗口登陆,并刷新父页面(使用layer)
<script type="text/javascript">
if (top != window){
// 显示遮罩
var shaded = layer.load(2, {
shade: [0.3,'#fff'] //0.1透明度的白色背景
});
//type1: 直接提示后跳转
// layer.msg('登陆过期,请重新登陆', {anim: 6},function(){
// top.location.href = window.location.href;
// });
//type2: 提示信息自主选择是否跳转
var notice = layer.alert('<p style="color:black;">登陆过期,请重新登陆</p>', {
skin: 'layui-layer-lan' //样式类名
,closeBtn: 0
,title: 0
,anim: 6 //动画类型
,btn: ['当前窗口登陆', '跳转登陆页面']
,yes: function(){
layer.close(shaded);
layer.close(notice);
}
,btn2: function(){
top.location.href = window.location.href;
}
});
}
</script>
也就是上面的type2,都是用到了layer,毕竟这么好看的插件。
type2 还需要在后台首页添加如下js:
$(function(){
if (top != window) {
top.location.href = top.location.href;
}
});
作用就是:当登陆进来的时候,如果后台首页不是展示在顶级窗口,那么就让顶级窗口自刷新。
这样就保证了,登陆以后还是在原来的界面。
效果如下:
type1: 三秒后直接跳转登录界面
type2:选择不跳转就是在当前弹出框登陆,登陆成功后刷新父级页面;选择跳转就和type1是一样的效果。