Skip to content

Instantly share code, notes, and snippets.

@theareba
Created September 26, 2016 12:49
Show Gist options
  • Save theareba/b103fc2fbab869285a31a5d6f12b014e to your computer and use it in GitHub Desktop.
Save theareba/b103fc2fbab869285a31a5d6f12b014e to your computer and use it in GitHub Desktop.
<h3>Client side IP geolocation using <a href="http://ipinfo.io">ipinfo.io</a></h3>
<hr/>
<div id="ip"></div>
<div id="country"></div>
<div id="welcome"></div>
<hr/>Full response: <pre id="details"></pre>
<div id="color-code" style="width: 300px; height: 300px;">
<input type="text" name="color" id="color" class="form-control" placeholder="Enter Color Code or color name">
</div>
<script>
$(document).ready(function(){
$.getJSON('https://ipinfo.io', function(response){
$("#ip").html("IP: " + response.ip);
$("#country").html("Country Code: " + response.country);
$("#details").html(JSON.stringify(response, null, 4));
if(response.country == "US") {
$("#color-code").css('background-color', 'red');
}
else if(response.country == "GB") {
$("#color-code").css('background-color', 'green');
}
else {
$("#color-code").css('background-color', 'purple');
}
})
$('#color').keyup(function(){
$('#color-code').css('background-color', $(this).val())
});
});
</script>
@theareba
Copy link
Author

@malditojavi here's the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment