Using Tencent's IP address library to do IP Physical address location _javascript Skills

Source: Internet
Author: User
Call:
Copy Code code as follows:

<script type=text/javascript src=http://fw.qq.com/ipaddress charset= "gb2312" ></script>
<script type=text/javascript>
document.write (Ipdata.join ('));
</script>

Display results as:
202.105.128.73, Shenzhen, Guangdong province
Do not IP as long as the region's words are called:
Copy Code code as follows:

<script Type=text/javascript src=http://fw.qq.com/ipaddress></script>
<script type=text/javascript>
document.write
(ipdata[2]);d ocument.write (ipdata[3]);
</script>

Display results as:
Shenzhen city, Guangdong province
The above code also has one trick: UTF-8 page references the processing of JS file encoding with external encoding as GBK
Http://fw.qq.com/ipaddress, and this interface provides JS for GBK encoded, because the page is UTF-8 encoded, so again using the return of the city name on my page is garbled, and can not be referenced. Through the charset settings, the UTF-8 page to introduce encoded GBK JavaScript file garbled problem. and no additional write functions are required to handle GBK UTF-8 encoding, and the same is true for JavaScript files encoded GBK page references encoded as UTF-8 if there is a garbled problem.

Source: http://shanyou.cnblogs.com/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.