Get User infos, Lang and Country Code

Get User infos, Lang and Country Code

by onigetoc

HTML

<h3>Client side IP geolocation using <a href="http://ipinfo.io" target="_blank">ipinfo.io</a></h3>

<hr/>
<div id="userLang"></div>
<div id="ip"></div>
<div id="address"></div>
<div id="country"></div>
<hr/>Full response: <pre id="details"></pre>

JavaScript

var userLang = navigator.language || navigator.userLanguage; 
//alert ("The language is: " + userLang);
$("#userLang").text("Lang: " +userLang);

// WITH IP: https://ipinfo.io/160.16.118.127
$.get("https://ipinfo.io", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#address").html("Location: " + response.city + ", " + response.region);
    $("#country").html("Country: " + response.country);
    $("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");

/*
$.get("http://ipinfo.io", function(response) {
    console.log(response.city, response.country);
}, "jsonp");
*/