其实很简单,只需要判断要跳转的页面是不是处于最外层即可,如下面代码
<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)
本文介绍了一种简单的方法,用于判断并确保当前页面在浏览器的顶层窗口打开,避免页面被嵌套在其他窗口中。通过JavaScript代码实现,只需在需要跳转的页面(如login.html/jsp)中加入特定的脚本,即可实现页面的顶层窗口强制跳转。
2万+

被折叠的 条评论
为什么被折叠?



