JS根据ip获取地区并屏蔽判断

通过IP获取地区(一)

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
var cityCode = returnCitySN.cid;
// qq = JSON.stringify(returnCitySN);
console.log(returnCitySN.cname);
</script>

通过IP获取地区(二)

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>

$.get("http://ip-api.com/json/?lang=zh-CN", function (returnCitySN) {
var city = returnCitySN.city || '';
var filterCity = ['北京', '上海', '深圳', '广州', '杭州'];
var aimUrl = 'http://www.baidu,com';
var isHasFilterCity = filterCity.some(function (item) {
return city.indexOf(item) > -1;
})
// console.log(returnCitySN);
// console.log(aimUrl);
if (isHasFilterCity) {
$("body").remove();
} else if (window.location.href !== aimUrl) {
window.location.href = aimUrl;
}
});
</script>

通过IP获取地区(三)

<script type="text/javascript" src="http://ip.ws.126.net/ipquery"></script>
<script type="text/javascript">
//获取值
var ipinfo = localAddress["province"] + localAddress["city"];
console.log(ipinfo);
//判断条件开始
if (ipinfo.toString().indexOf("北京") != -1 || ipinfo.toString().indexOf("上海") != -1 || ipinfo.toString().indexOf("广州") != -1
|| ipinfo.toString().indexOf("深圳") != -1) {
window.location.href = "http://XXXX.com";
//符合屏蔽地区就跳转
} else {
//否则就看你自己定义了
}
</script>