Skip to content Skip to sidebar Skip to footer

Common Idiom To Avoid Ie Throw: Error: 'console' Is Undefined

I've installed firebug and I wrote all these log statements. I've tested my app in IE and of course I've got 'undefined' error. What's the common idiom to avoid this. I don't r

Solution 1:

i usually make a wrapper function like so:

functionlog(obj) {
    if (window.console && console.log) console.log(obj);
}

or you could do something like this at the beginning of your script file/element:

if (!window.console) { 
    window.console = {
        log: function(obj){ /* define own logging function here, or leave empty */ }
    };
}

Solution 2:

Paul Irish has a better wrapper for console.log().

http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/

This allows multiple arguments, and provides a history (for debugging) in case no console is there or (eg Firebug Lite) the console is created later.

Post a Comment for "Common Idiom To Avoid Ie Throw: Error: 'console' Is Undefined"