I want to show an entry popup only to those who are visiting from India using JavaScript.
Asked
Active
Viewed 98 times
-4
-
1You need to give more detail when asking questions and describe what you have already tried. – Philip Deatherage Aug 01 '17 at 10:20
-
Possible duplicate: https://stackoverflow.com/questions/6747833/how-can-i-find-a-user-s-country-using-html5-geolocation (and numerous duplicates linked from there) – freedomn-m Aug 01 '17 at 10:39
2 Answers
1
Firstly get the IP of the visitor
$(document).ready(function () {
$.getJSON("http://jsonip.com/?callback=?", function (data) {
console.log(data);
alert(data.ip);
});
});
Then use a service that actually returns country names, like FreeGeoIp
$.getJSON("http://freegeoip.net/json/", function (data) {
var country = data.country_name;
var ip = data.ip;
});
After that shw your popup
if(country == 'India') {
//......
}

Munawir
- 3,346
- 9
- 33
- 51
-
-
1this works for me $(window).load(function () { $.get("http://ipinfo.io", function (response) { var country = response.country; //alert(country); if (country == 'IN') { $("#myModal").modal({ backdrop: 'static', keyboard: false }); } }, "jsonp"); }); – Mahesha N C Aug 01 '17 at 11:14