使用IE的geoPlugin undefine变量

时间:2012-09-28 01:04:20

标签: javascript internet-explorer-8 internet-explorer-9 cross-domain

我有一些使用geoPlugin的网站,并且在9月24日的微软IE更新后,我遇到了一些奇怪的问题。我第一次注意到我的nivo滑块没有显示在我的主页上,所以我挖到控制台找到了

SCRIPT5009: 'geoplugin_countryCode' is undefined

然后,我在Google Chrome中调试了同一页面,一切正常。我试图破译有关该更新的KB2744842公告

这是我的javascript:

<script src="https://ssl.geoplugin.net/javascript.gp" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var country = geoplugin_countryCode();

        if(country === 'CA'){
            $('#notification').html('<div class="attention" style="display: none;">You are in Canada</div>');
            $('.attention').fadeIn('slow');
            $('html, body').animate({ scrollTop: 0 }, 'slow');
        }else if(country != 'US'){
            $('#notification').html('<div class="attention" style="display: none;">You are in the USA</div>');
            $('.attention').fadeIn('slow');
            $('html, body').animate({ scrollTop: 0 }, 'slow');
        }else{
            //nothing stupid IE
        }

    });
    $('.geoClose').live('click', function() {
        console.log('geoplugin notify closed');
        document.cookie = 'geoClose=true;'
    });
</script>

HTML:

<div id="wrapper">
  <div id="header">Header Text</div>
  <div id="notification"></div>
  <div id="content">Content Here!</div>
  <div id="footer"></div>
</div>​

1 个答案:

答案 0 :(得分:0)

geoPlugin最近更改了一些有关SSL请求的政策,显然IE不会遵循其他浏览时实施的重定向。

结果代码:

<script src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>
<script src="http://www.geoplugin.net/statistics.gp" type="text/javascript"></script>
<!--<script src="https://ssl.geoplugin.net/javascript.gp" type="text/javascript"></script>-->
<script type="text/javascript">
//<![CDATA[
    $(document).ready(function() {
        var country = geoplugin_countryCode();

        if(country === 'CA'){
            $('#notification').html('<div class="attention" style="display: none;">You are in Canada</div>');
            $('.attention').fadeIn('slow');
            $('html, body').animate({ scrollTop: 0 }, 'slow');
        }else if(country != 'US'){
            $('#notification').html('<div class="attention" style="display: none;">You are in the USA</div>');
            $('.attention').fadeIn('slow');
            $('html, body').animate({ scrollTop: 0 }, 'slow');
        }else{
            //nothing stupid IE
        }

    });
    $('.geoClose').live('click', function() {
        console.log('geoplugin notify closed');
        document.cookie = 'geoClose=true;'
    });
//]]>
</script>