首页 > 语言 > JavaScript > 正文

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

2024-05-06 14:24:42
字体:
来源:转载
供稿:网友
代码如下:
<script type="text/javascript">
if(self!=top){top.location=self.location;}
var ref=document.referrer;
var domains=new Array("Vevb.com/","jb51.cn/","jb51.com.cn/");
var refpass=false;
for(i=0;i<=domains.length;i++){if(ref.indexOf(domains[i])>0){refpass=true;break;}}
if(ref==""){refpass=true}
if(!refpass){window.location.href='//www.Vevb.com';}
</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,'www.Vevb.com') == false){window.location.href="//www.Vevb.com";}
</script>

下面我们一个网站开发中用到的

代码如下:
function gotourl()
{
 var url = "//www.Vevb.com";
 var localurl = document.url;
 if( localurl.substring(0,url.length) != url )
 {
  location.href=url;
 }
}
gotourl();

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选