Created
September 26, 2016 12:49
-
-
Save theareba/b103fc2fbab869285a31a5d6f12b014e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@malditojavi here's the code