【问题标题】:Managing redirection according to IP Location根据 IP 位置管理重定向
【发布时间】:2015-05-06 20:22:55
【问题描述】:

当 IP 来自另一个国家/地区时,我们使用 Geo IP 重定向到国际站点,但我们遇到了一些问题,因此我们想询问用户是否希望保留在常规站点中或去国际。

我有一个fancybox(如jquery),当IP 从另一个国家/地区查看时会被触发,现在我想知道我可以做些什么来缓存(或类似的东西)答案并且不再显示该消息。

因为如果你转到另一个页面,它会再次被触发

jQuery(document).ready(function(){

    jQuery.ajax({
        url: window.location.origin + '/mysite/geoIp/geoip.php',
        success: function(result){
            var json = jQuery.parseJSON(result);
            if (json.countryCode !== 'MX') {
                jQuery.fancybox({ //Fancybox with the question
                    href: '#country-box', 
                    modal: true
                });
            }
        }
    });

});

【问题讨论】:

    标签: jquery redirect caching response geoip


    【解决方案1】:

    我认为最简单的方法是在用户看到模态框后设置会话 cookie。您可以使用 jquery cookie 库将其保存在 jQuery 中 - https://github.com/carhartl/jquery-cookie

    在用户回答后设置 cookie:

    $.cookie('language_modal_seen', 'value');
    

    在显示模态之前检查它的存在

    if($.cookie('language_modal_seen') === 'value'){
        //show the modal or not
    }
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      相关资源
      最近更新 更多