getIp(获取ip所对应的城市名称):
/*获取当前城市所在的省*/
var myprovince = remote_ip_info['province'];
/*获取当前城市所在的市*/
var mycity = remote_ip_info['city'];
/*获取当前城市所在的区*/
var mydistrict = remote_ip_info['district'];
$(function(){
$("#city_1").citySelect({
prov:myprovince,
city:mycity
});
});
通过IP定位初始为当前城市所在页面
/*通过IP定位初始城市设置*/
/*判断当前省份不为空*/
if(myprovince != undefined || mycity != undefined){
/*读取cookie:由62行代码可看出 cityName对应的内容为 $cityname*/
var cityName = $.cookie("cityName");
/*将城市当前所在城市赋给¥city,然后进行判断*/
$city = mycity;
switch($city){
case '城市名称1':
$cityname = 'url链接1';
break;
case '城市名称2':
$cityname = 'url链接2';
break;
case '城市名称4':
$cityname = 'url链接4';
break;
case '城市名称5':
$cityname = 'url链接5';
break;
default:
$cityname = '其它城市跳转的url链接地址';
break;
}
/*创建字符串:二级域名*/
$go_url =$cityname;
/*将生成的二级域名写入网址栏*/
window.location.href = $go_url;
/*.新添加一个会话 cookie:$cityname为存储的内容*/
$.cookie("cityName", $cityname);
}