1
我想在國際觀衆訪問我的美國基地網站時顯示彈出窗口。最好用JavaScript或jQuery框架。任何建議?向國際用戶顯示信息
我想在國際觀衆訪問我的美國基地網站時顯示彈出窗口。最好用JavaScript或jQuery框架。任何建議?向國際用戶顯示信息
下面是使用jQuery,http://smart-ip.net/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();
}
}
});
你要確定訪問者的IP地址是來自另一個國家,所以這可能是一個有益的SO鏈接:http://計算器。 com/questions/4937517/ip-to-location-using-javascript - 但我不知道你真的需要知道什麼,比如它是否檢測到外部IP地址或什麼。 – birryree 2012-04-19 19:03:29
另一種方法是查看瀏覽器語言是否爲英語。搜索條件是「本地化」。 [這是一個jQuery方法。](https://github.com/coderifous/jquery-localize) – DOK 2012-04-19 19:06:26