Console.log IE9 issue

13,847

Solution 1

If you want to use console.log() and have it not bomb out in IE when the IE debugger is not running, you can place the following in your javascript at the global scope before any console.log() statements execute to give you a dummy console.log() that will keep your console.log() statements from causing errors:

if (!window.console) {window.console = {};}
if (!console.log) {console.log = function() {};}

Of course, if you actually want to see the console.log() output in IE, then you will have to run the IE debugger which will cause console.log() to get defined or use some other debugging environment that defines it.

Solution 2

There's no console.log in IE unless you have Firebug light on. It's gonna turn into a undefined method/variable error

More information here: Does IE9 support console.log, and is it a real function?

Share:
13,847
jQuerybeast
Author by

jQuerybeast

A kid stepping an inch forward every day.

Updated on July 30, 2022

Comments

  • jQuerybeast
    jQuerybeast almost 2 years

    I made a simple Task Manager using local.storage and I'm using console.log to set some variables but with that, the entire task app doesn't work in IE.

    Is there any alternative method of doing this?

    Here is the fiddle of the working Task Manager in every other browser: http://jsfiddle.net/cRse9c/

  • jQuerybeast
    jQuerybeast almost 13 years
    Is there any alternative method of doing it?
  • corroded
    corroded almost 13 years
    I usually do alerts instead of console.log, but if you want objects, you can try firebug light or follow that link. i think yo ucan turn on developer tools
  • Zach Lysobey
    Zach Lysobey about 11 years
    This question has some other useful info on using console.log in production: stackoverflow.com/questions/8002116/…
  • williamsandonz
    williamsandonz over 10 years
    Thanks, this is very handy!!
  • jfriend00
    jfriend00 about 9 years
    @user3388971 - I had to rollback your edit. var does not scope to the block level in Javascript and your edit removing var so it was an implicit declaration would have not worked in strict mode. I changed it to refer to the window object.