下面是在H5页面中获取访问者IP地址的例子:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>js获取访问者IP及所在地</title>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
</head>
<body>
<script type="text/javascript">
console.log(returnCitySN);
</script>
</body>
</html>
输出:
{"cip": "116.236.177.182", "cid": "310105", "cname": "上海市长宁区"}
就这样,我们就能获取到访问者IP及所在地啦。