【问题标题】:Meteor: Fixing console is undefined in Internet ExplorerMeteor:修复控制台在 Internet Explorer 中未定义
【发布时间】:2014-10-13 21:03:07
【问题描述】:

我尝试按照其他 SO 答案中的建议修复错误,但我继续收到错误。任何想法为什么?

我尝试使用此处的以下修复:'console' is undefined error for Internet Explorer 并将其粘贴到客户端 js 文件中的 Meteor.startup 中,但它不起作用。

Meteor.startup(function () {
  /**
   * Protect window.console method calls, e.g. console is not defined on IE
   * unless dev tools are open, and IE doesn't define console.debug
   */
  (function() {
    if (!window.console) {
      window.console = {};
    }
    // union of Chrome, FF, IE, and Safari console methods
    var m = [
      "log", "info", "warn", "error", "debug", "trace", "dir", "group",
      "groupCollapsed", "groupEnd", "time", "timeEnd", "profile", "profileEnd",
      "dirxml", "assert", "count", "markTimeline", "timeStamp", "clear"
    ];
    // define undefined methods as noops to prevent errors
    for (var i = 0; i < m.length; i++) {
      if (!window.console[m[i]]) {
        window.console[m[i]] = function() {};
      }    
    } 
  })();
});

我应该将此代码粘贴到其他地方吗?

【问题讨论】:

  • 为什么不在Meteor.startup之外做呢?所以包初始化代码不会抛出ReferenceError的?

标签: javascript internet-explorer meteor


【解决方案1】:

尝试将代码放在Meteor.startup() 函数之外。这必须在您在任何地方调用console.log 之前执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-20
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多