轉載來自:https://blog.csdn.net/qq_35855343/article/details/108706136
現在用的比較多的第三方免費開放接口一般是搜狐提供的接口:http://pv.sohu.com/cityjson?ie=utf-8。
所以通過script標簽引入這個接口就可以了,這樣還可以避免跨域的問題。
話不多說,上代碼(親測有效):
<!DOCTYPE html> <html> <head> <title>get Ip and MAC!</title> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> </head> <body> <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> <script type="text/javascript"> document.write(returnCitySN["cip"]+','+returnCitySN["cname"]) </script> </body> </html>