js BOM判断当前窗口是否最顶层。

<script>
//顶级窗口链接!=当前窗口链接
//top.location != self.location 就是说父窗体的 url当前窗体的url和是不是相同
//如果相同执行top.location=self.location;},把窗体的url设成和本窗体一样。这个是为了防止别的网站嵌入你的网站的内容(比如用iframe嵌入的你的网站的页面)

if(top.location!=self.location){
top.location
= "<%=basePath%>/login.jsp";
}
else{
window.location.href
= "<%=basePath%>/login.jsp";
}

</script>
参考:https:
//blog.csdn.net/yueritian/article/details/37996731
https://zhidao.baidu.com/question/257914116.html

菜鸟教程:

window.top//顶级的窗口

window.self//当前的窗口

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script>
function check(){
    if (window.top!=window.self) {
        document.write("<p>这个窗口不是最顶层窗口!我在一个框架?</p>")
    }
    else{ 
        document.write("<p>这个窗口是最顶层窗口!</p>")
    } 
}
</script>
</head>
<body>
    
<input type="button" onclick="check()" value="检查窗口">
    
</body>
</html>
原文地址:https://www.cnblogs.com/xiaobaicai123/p/10578743.html