编程爱好者之家
一:先引用js
<script src="http://pv.sohu.com/cityjson?ie=gb2312" charset="GB2312"></script>
此js的返回结果为如下示例
var returnCitySN = {"cip": "ip地址", "cid": "310000", "cname": "上海市"};
二:判断地区并做相应操作
<script type=text/javascript> var a_city = returnCitySN.cname; if (a_city.indexOf('上海') != -1 ) { window.location.href = ' //判断如果是上海就跳转 } </script>