Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 允许URL进入网站?_Javascript_Jquery - Fatal编程技术网

Javascript 允许URL进入网站?

Javascript 允许URL进入网站?,javascript,jquery,Javascript,Jquery,在页面加载之前,我需要允许访问几个URL,其余的URL将被重定向 expample: If user trying to access these urls they will be allowed and other urls will be redirected to google.com (example) http://mysite.com/site/Dept/IT http://mysite.com/site/Dept/IT/ITWS http://mysite.com/si

在页面加载之前,我需要允许访问几个URL,其余的URL将被重定向

expample: If user trying to access these urls they will be allowed and 
   other urls will be redirected to google.com (example)

http://mysite.com/site/Dept/IT
http://mysite.com/site/Dept/IT/ITWS
http://mysite.com/site/dept/ce
http://mysite.com/site/dept/mkt
http://mysite.com/site/teams/dgt
http://mysite.com/site/teams/mm

如何在jQuery中实现这一点?将arraylist设置为URL并对照arraylist进行检查并允许使用它们。

您可以在每个页面上加载Javascript片段,如果当前页面的URL与其中任何一个都不匹配,它将重定向用户

$(document).ready(function() {
    var urls = ["http://mysite.com/site/Dept/IT",
              "http://mysite.com/site/Dept/IT/ITWS",
              "http://mysite.com/site/dept/ce",
              "http://mysite.com/site/dept/mkt",
              "http://mysite.com/site/teams/dgt",
              "http://mysite.com/site/teams/mm"];
    if ($.inArray(document.location.href, urls) == -1) {
      window.location = "http://www.google.com/";
    }
});

您可以在每个页面上加载Javascript代码段,如果当前页面的url与其中任何一个都不匹配,它将重定向用户

$(document).ready(function() {
    var urls = ["http://mysite.com/site/Dept/IT",
              "http://mysite.com/site/Dept/IT/ITWS",
              "http://mysite.com/site/dept/ce",
              "http://mysite.com/site/dept/mkt",
              "http://mysite.com/site/teams/dgt",
              "http://mysite.com/site/teams/mm"];
    if ($.inArray(document.location.href, urls) == -1) {
      window.location = "http://www.google.com/";
    }
});

如果您真的想拒绝服务器上的特殊URL,我建议您在服务器端这样做。


如果你真的想拒绝服务器上的特殊URL,我真的建议你在服务器端这样做。

如果你不反对在网页上使用PHP,这很容易用PHP做到。如果我关闭了JavaScript怎么办?@Wex:它是asp.net母版页。@James123:jQuery不是它自己的语言,它是一个JavaScript库。因此,没有JavaScript,没有jQuery。这应该在服务器级别处理,而不是在应用程序级别。阅读您正在使用的任何服务器的配置选项。寻找重定向或URL重写。如果你不反对在网页中使用PHP,这在PHP中很容易做到。如果我关闭了JavaScript怎么办?@Wex:它是asp.net母版页。@James123:jQuery不是它自己的语言,它是一个JavaScript库。因此,没有JavaScript,没有jQuery。这应该在服务器级别处理,而不是在应用程序级别。阅读您正在使用的任何服务器的配置选项。查找重定向或URL重写。