用js判断访问来路

  199 次阅读

CONTENT

用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面,需要的朋友可以参考下。

方法一:

  1. <script type="text/javascript">
    
  2. if(self!=top){top.location=self.location;}
    
  3. var ref=document.referrer;
    
  4. var domains=new Array("2kss.com/","22vd.com/","7uup.com/");
    
  5. var refpass=false;
    
  6. for(i=0;i<=domains.length;i++){if(ref.indexOf(domains[i])>0){refpass=true;break;}}
    
  7. if(ref==""){refpass=true}
    
  8. if(!refpass){window.location.href='http://www.22vd.com';}
    
  9. </script>

方法二:

  1. <script>
    
  2. function isMatch(str1,str2)
    
  3. { 
    
  4. var index = str1.indexOf(str2);
    
  5. if(index==-1) return false;
    
  6. return true;
    
  7. }
    
  8. alert(window.location.hostname);
    
  9. if (isMatch(window.location.hostname,'www.22vd.com') == false){window.location.href="http://www.22vd.com";}
    
  10. </script>

方法三:

  1. function gotourl()
  2. {
  3.  var url = "http://www.22vd.com";
  4.  var localurl = document.url;
  5.  if( localurl.substring(0,url.length) != url )
  6.  {
  7.   location.href=url;
  8.  }
  9. }
  10. gotourl();

Comments | NOTHING

暂无评论...