feihu 发表于 2017-7-3 22:53:21

用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面

本帖最后由 feihu 于 2017-7-3 22:56 编辑

用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面<script type="text/javascript">
if(self!=top){top.location=self.location;}
var ref=document.referrer;
var domains=new Array("cnblackhat.com/","yunrank.cn/","bbs.cnblackhat.com/");
var refpass=false;
for(i=0;i<=domains.length;i++){if(ref.indexOf(domains)>0){refpass=true;break;}}
if(ref==""){refpass=true}
if(!refpass){window.location.;}
</script>推荐<script>
function isMatch(str1,str2)
{  
var index = str1.indexOf(str2);
if(index==-1) return false;
return true;
}
alert(window.location.hostname);
if (isMatch(window.location.hostname,'bbs.cnblackhat.com') == false){window.location.href="https://bbs.cnblackhat.com";}
</script>下面我们一个网站开发中用到的function gotourl()
{
var url = "https://bbs.cnblackhat.com";
var localurl = document.url;
if( localurl.substring(0,url.length) != url )
{
  location.href=url;
}
}
gotourl();

huangjia 发表于 2017-7-4 07:08:04

谢谢分享,学习了
页: [1]
查看完整版本: 用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面