session过期后iframe页面如何跳转到parent页面

session过期后如果在iframe里操作就会返回到login.html,可是这个页面还在iframe里面如果再次登陆就会出现iframe嵌套的现象,我们这样来解决。

 在login.html里面加上这个就可以了.

function checkParent(){

    if(window.parent.length>0){ 
        window.parent.location="login.html"; 
    }
}

<body onload="checkParent();">
……
</body>
The window.length property returns the number of frames contained in a window.

当然可以通过这个原理:

Response.Write("<script>window.parent.parent.location.href='index.aspx?error=登陆超时!'</script>");
    Response.End();

有几个iframe就可以弄几个parent

原文地址:https://www.cnblogs.com/lyl6796910/p/3618389.html