前端随记(禁止直接页面跳转 、http-equiv=“refresh“ 网页自动跳转)

1、禁止直接页面跳转.js

window.onload=function(){
    //排除特定页面
    if (this.location.href.indexOf("UI/src/views/home/console.html") > 0 || this.location.href.indexOf("UI/src/views/user/login.html") > 0 ||
        this.location.href.indexOf("UI/src/views/user/forget.html") > 0 || this.location.href.indexOf("UI/src/views/user/forget.html") > 0 || this.location.href.indexOf("UI/src/views/user/reg.html") > 0
        || this.location.href.split("UI/src/views/")[1] == ""
    ) {
        return;
    }
    //禁止直接页面跳转
    //console.log(this.location.href.split("UI/src/views/")[1]=="");
    if (top.location.href == this.location.href && this.location.href.split("UI/src/views/")[0] != "") {
        location.replace("../StatePage/IllegalJumpPage.html");
        return;
    }
}


// http://192.168.1.17:8088/UI/src/views/ActivityCenter/CreateActivity.html

效果是:open in new tab 或者复制里面的url 到新建网页运行访问的话,直接让其跳转进入IllegalJumpPage.html 。

2 META http-equiv=“refresh” 实现网页自动跳转

default.htm内容:

  <meta http-equiv="refresh" content="0; url=UI\src\views\user\login.html" />

环境如下:IIS项目文件夹下创建个default.htm ,IIS的默认文档将default.htm置顶。

效果是访问:http://192.168.1.19:8063/ 自动跳转> http://192.168.1.19:8063/UI/src/views/user/login.html

再添加个例子:

root@ggwlq-PC:/var/www/html# cat index.php 
<head>
<meta http-equiv="refresh" content="0;url=IT_home/IT_login.php"> 
</head>

在这里插入图片描述

参考:https://www.cnblogs.com/lixihuan/p/6824871.html

你可能感兴趣的:(前端,javascript,web,js)