【问题标题】:Display message for international users为国际用户显示消息
【发布时间】:2012-04-19 19:00:11
【问题描述】:

我想在国际访问者访问我的美国基地网站时显示一个弹出窗口。最好使用 javascript 或 jQuery 框架。有什么建议吗?

【问题讨论】:

标签: javascript jquery geolocation


【解决方案1】:

这是一个使用 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();
        }
    }
});

【讨论】:

    猜你喜欢
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    相关资源
    最近更新 更多