'console' is undefined error for Internet Explorer

前端 未结 21 1235
-上瘾入骨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:17

    Noticed that OP is using Firebug with IE, so assume it's Firebug Lite. This is a funky situation as console gets defined in IE when the debugger window is opened, but what happens when Firebug is already running? Not sure, but perhaps the "firebugx.js" method might be a good way to test in this situation:

    source:

    https://code.google.com/p/fbug/source/browse/branches/firebug1.2/lite/firebugx.js?r=187

        if (!window.console || !console.firebug) {
            var names = [
                "log", "debug", "info", "warn", "error", "assert",
                "dir","dirxml","group","groupEnd","time","timeEnd",
                "count","trace","profile","profileEnd"
            ];
            window.console = {};
            for (var i = 0; i < names.length; ++i)
                window.console[names[i]] = function() {}
        }
    

    (updated links 12/2014)

提交回复
热议问题