js獲取手機ip
阿新 • • 發佈:2019-01-02
在網上各種查詢,最後決定調用搜狐介面
搜狐IP地址查詢介面(預設GBK):http://pv.sohu.com/cityjson
搜狐IP地址查詢介面(可設定編碼):http://pv.sohu.com/cityjson?ie=utf-8
程式碼中獲取
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>獲取ip地址</title>
</head>
<body >
</body>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
//瀏覽器返回結果:(前提是需要有網路)
//var returnCitySN = {"cip": "14.153.20.119", "cid": "440300", "cname": "廣東省深圳市"};
console.log(returnCitySN.cip);
</script>
</html>