其實很簡單,只需要判斷要跳轉的頁面是不是處於最外層即可,如下面代碼
<script language="JavaScript">
// 如果當前窗口不是頂級窗口,就強制修改爲頂級窗口
if (window != top) {
top.location.href = location.href;
}
</script>
// 補充:
// window.location.href、location.href 是本頁面跳轉
// parent.location.href 是上一層頁面跳轉
// top.location.href 是最外層的頁面跳轉
- 只需要將要跳轉的頁面中加上上述代碼即可(eg:login.html / jsp)