- 时间:2020-10-06 17:12 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面
[url=http://www.1sucai.cn]</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.1sucai.cn') == false){window.location.href="http://www.1sucai.cn";}
</script>
下面我们一个网站开发中用到的
function gotourl()
{
var url = "http://www.1sucai.cn";
var localurl = document.url;
if( localurl.substring(0,url.length) != url )
{
location.href=url;
}
}
gotourl();