当前位置: 主页 > 织梦新闻 >

JS记录网站是否第一次访问并跳转

admin 2020-06-29 0条评论

JS记录网站是否第一次访问并跳转:

<script type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8"></script>//根据IP获得所在省份信息。返回格式:var returnCitySN = {"cip": "171.X.X.X", "cid": "000000", "cname": "四川省"};
<script>    
if(window.name == "")//第一次访问跳转
{
var url = window.location.host;//获取域名
url = url.split(".")[0] ;//提取二级域名入b.aaa.com得到b
var city = returnCitySN.cname;//获得接口省份信息
city = city.replace("省","");
city = city.replace("市",""); //去掉省和直辖市显示
var cityArray = [["北京","beijing"],["上海","shanghai"],["广东","guangzhou"],["深圳","shenchou"],["天津","tianjin"],["重庆","chongqing"],["四川","chengdu"],["江苏","njing"],["浙江","hangzhou"],["辽宁","shenyang"],["湖北","wuhan"],["江西","nanchang"],["湖南","changsha"],["河南","zhengzhou"],["吉林","changchun"],["黑龙江","haerbin"],["陕西","xian"],["云南","kunming"],["青海","xining"],["河北","qinhuangdao"],["广西","nanning"]];
for(var i=0;i<cityArray.length;i++){
  if(city == cityArray[i][0]){
  if(url != cityArray[i][1])
  {
var gourl = 'http://'+cityArray[i][1]+'.aaa.com/';//根据身份,跳转到二级域名
alert(gourl); 
//window.location.href=gourl; 
  }
  }

}
}
   window.name = "00";//赋值,老访客,不跳转
function setCookie(cname,cvalue,exdays){var d = new Date();d.setTime(d.getTime()+(exdays*24*60*60*1000));var expires = "expires="+d.toGMTString();document.cookie = cname + "=" + cvalue + "; " + expires;}function getCookie(cname){var name = cname + "=";var ca = document.cookie.split(';');for(var i=0; i<ca.length; i++)   {  var c = ca[i].trim();  if (c.indexOf(name)==0) return c.substring(name.length,c.length);}return "";}function checkCookie(){var user=getCookie("username");if (user!=""){   
alert("Welcome again " + user);  }else   {
user = prompt("Please enter your name:","");  if (user!="" && user!=null) {    setCookie("username",user,2/(3600*24));    }  }}window.οnlοad=function(){  checkCookie()}    

</script>

关于我

欢迎加我的QQ号交流


搜索
广而告之
友情链接