I would like to display a pop-up when international visitors visit my U.S. bases website. Preferably with javascript or the jQuery framework. Any recommendations?
Asked
Active
Viewed 477 times
1
-
3You want to determine if visitor IP addresses are from another country, so this might be a helpful SO link: http://stackoverflow.com/questions/4937517/ip-to-location-using-javascript - but I don't know what you really need to know, like if it's detecting foreign IP addresses or what. – wkl Apr 19 '12 at 19:03
-
A different approach would be to see if the browser language is English or not. The search term for that is "localization". [Here is one jQuery approach for it.](https://github.com/coderifous/jquery-localize) – DOK Apr 19 '12 at 19:06
1 Answers
0
Here is a solution using jQuery, http://smart-ip.net/, and https://github.com/carhartl/jquery-cookie:
$(document).ready(function() {
if (!$.cookie("international")) {
$.getJSON("http://smart-ip.net/geoip-json?callback=?", function(data){
if (data.countryCode !== "US") {
popUpFunction();
$.cookie("international", "yes", { expires: 365 });
} else {
$.cookie("international", "no", { expires: 365 });
}
});
} else {
if ($.cookie("international") === "yes") {
popUpFunction();
}
}
});

jlaceda
- 866
- 6
- 11