'console' is undefined error for Internet Explorer

前端 未结 21 1337
-上瘾入骨i
-上瘾入骨i 2020-11-22 04:49

I\'m using Firebug and have some statements like:

console.log(\"...\");

in my page. In IE8 (probably earlier versions too) I get script err

21条回答
  •  礼貌的吻别
    2020-11-22 05:21

    For IE8 or console support limited to console.log (no debug, trace, ...) you can do the following:

    • If console OR console.log undefined: Create dummy functions for console functions (trace, debug, log, ...)

      window.console = { debug : function() {}, ...};

    • Else if console.log is defined (IE8) AND console.debug (any other) is not defined: redirect all logging functions to console.log, this allows to keep those logs !

      window.console = { debug : window.console.log, ...};

    Not sure about the assert support in various IE versions, but any suggestions are welcome. Also posted this answer here: How can I use console logging in Internet Explorer?

提交回复
热议问题