开发者

How can I get rid of these 'console.log is not defined' errors in IE?

...without removing the calls to console.log obviously. It doesn't need to log or do anything, I just want it to not show an error. I'm trying

if (!window.console) {

    window.console = {

        log: function() {},

        error: function() {},

        warn: function() {}

    }

}

But that doesn'开发者_开发问答t seem to fix it.


Use debug.log with the following js file instead. It kicks ass.

http://benalman.com/projects/javascript-debug-console-log/


Just taking a wild guess, but

if (typeof window.console !== "undefined") { ... }

would probably solve your issue.


window.console = window.console || {log: function() {}};


I'm using

function trace(s) {
    try { 
        console.log(s); 
    } catch (e) { 
        //alert(s); 
    }
};

trace(foo);

Uncomment the alert if you want to get it in IE.

(I got it from another thread here in SO but i don't remember what was)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜