Skip to content Skip to sidebar Skip to footer

Find The Three Letter Country Code Using Html And Javascript

I am trying to find user's location meaning in which country he is browsing. I need to use HTML and Javascript for this. I have seen various posts on stackoverflow on this in whic

Solution 1:

ipinfo.io does NOT provide a three-letter country code. You'll have to manually produce an array:

var threeLtrCC.US = 'USA';
 var threeLtrCC.IN = 'IND';
 ...
 $.get("http://ipinfo.io", function (response) {
     var cc = threeLtrCC[response.country];
     $('#newURL').text('some_url?countryCode=' + cc);
     $('#newURL').attr('href','some_url?countryCode=' + cc);         
     $("#details").html(JSON.stringify(response, null, 4));
 }, "jsonp");

and then use response.country as the key to find the value from your homemade array.

HTML

<a id="newURL"></a>

Solution 2:

I don't think ipinfo provides a three letter country code.We have to use an array with all the available country code and match with the three letter country code.

http://www.worldatlas.com/aatlas/ctycodes.htm

Hope it help's

Post a Comment for "Find The Three Letter Country Code Using Html And Javascript"