A method to achieve distal targeting ip

Verbatim https://www.dazhuanlan.com/2019/08/26/5d62f8a89db51/


Introduce two kinds of API, the first one is Sohu API, the second is Baidu API
first:

1
2
3
4
5
6
7
8
9
10
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html> charset=utf-8" />
<title>基于搜狐JS接口得到本机IP</title>
<script type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
</head>
<body>
<script> document.write(returnCitySN["cip"]+','+returnCitySN["cname"])</script>
</body>
</html>

The second:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
< HTML > < head > < Meta HTTP-equiv = "Content-Type" Content = "text / HTML; charset = UTF-8" /> < title > Auto Obtain current city visitors </ title > < Script of the type = "text / JavaScript" src = "http://api.map.baidu.com/api?v=2.0&ak= your API key" > </ Script > </ head > < body > < div the above mentioned id = "bdMapBox"style=






"Run the display: none;" > </ div > < Script of the type = "text / JavaScript" > // Baidu Maps API function var = new new BMap.Map the Map ( "bdMapBox"); var nowCity = new new BMap.LocalCity (); nowCity.get (bdGetPosition); function bdGetPosition (Result) { var cityName = result.name; // current city name / * custom code * / atCity.innerHTML = cityName; / * custom code * / } </ Script > < the p- > your current city as: < span the above mentioned id = "atCity" ></span











></p>
</body>
</html>

The first is recommended, because Sohu API without registering, so.

The following is a modification of the method of Sohu API:

1. After configured API, can not work at the site http, but https can

Solution: The API is written in https to http.

2. Once you've configured above, click on the web page only shows their ip address (and pjax related)

Solution: The document.write changed document.getElementById

Modified version (may modify the size and color):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<html>
<head>
<meta http-equiv="Content-Type" content="text/html> charset=utf-8" />
<title>基于搜狐JS接口得到本机IP</title>
<script type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
</head>
<body>
<p id="htmlip"></p>
<script>
var jsip=returnCitySN["cip"]+","+returnCitySN["cname"];
document.getElementById("htmlip").style.color="你需要的颜色";
document.getElementById("htmlip").style.fontSize="你需要的大小:xxpx)";
document.getElementById("htmlip").innerHTML=jsip;
</script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/petewell/p/11410431.html