"控制台未定义" IE8中的错误

时间:2015-01-14 22:43:40

标签: javascript css internet-explorer-8 console

很抱歉,如果我听起来像是破纪录,但我找不到相关的修复方法。

我正在尝试运行此脚本,根据“季节”(南半球)更改网站的外观和感觉,我相信'控制台'是未定义的错误,我得到的是杀死此脚本。图像,颜色等...不显示在IE8(不幸的是必要的浏览器),但在Chrome和> IE9中它工作正常。所以我追求IE8特定的FIX

这是代码:

<script>
    // JavaScript Document
    function getSeason(d) {
     d = d || new Date();
     var mon = d.getMonth() + 1;  // Adjust to be indexed from 1
     var day = d.getDate();
     var seasons = ['summer','autumn','winter','spring'];


     // Do silly seasons here
     if (mon == 12) {
      if (day >= 13 && day <= 27) {
       return 'xmas';
      }
      if (day >= 28 && day <= 31) {
       return 'nye';
      }
     }

     // If wasn't a silly season, do others
     mon = Math.floor((mon % 12) / 3);
     return seasons[mon];
     }

    console.log('Currently it is ' + getSeason()); // Currently it is summer

    $(document).ready(function(){
    document.body.className = getSeason();
    });
    </script>

我确实在页面中运行了其他代码(例如“时钟”和“幻灯片”以及“复制到剪贴板”),但出于某种原因......这个代码不起作用。

拜托,我希望有人可以帮我解决这个问题。再次,如果我提出已被问过的问题,我很抱歉,但我找不到相关的答案。如果您需要更多信息,请询问。

1 个答案:

答案 0 :(得分:1)

在代码的开头添加:

if (typeof console == "undefined") console = {
    log: function() {},
    debug: function() {},
    error: function() {}
};