Blocking Users by Country
// List of countries we want to block
// To see this in action add your country code to the array
var blacklist = ['ZM', 'CA', 'CH', 'IN']
// Getting the country code from the user's IP
$.get("https://ipforensics.net/api/v1/origin?apikey=APIKEY", function (response) {
// Checking if the user's country code is in the blacklist
// You could inverse the logic here to use a whitelist instead
if (blacklist.includes(response.meta_data.geolocation.code)) {
alert('This content is not available at your location.');
} else {
alert("You're allowed to see this!")
}
}, "jsonp");PreviousHTML5 Geolocation with IpForensics fallbackNextDetecting Users Currency or Currency Personalisation
Last updated