0

Possible Duplicate:
Common idiom to avoid IE throw: Error: 'console' is undefined
'console' is undefined error for internet explorer

Is there a reliable way I can guard against "console.log" causing a bug in IE?

While I find console.log extremely useful, it is always a source of grief with Internet Explorer.

If it's just statements that I have left in my code, that's fine, I could deal with that. But sometimes I find that there are "console.log" calls in JavaScript libraries I am using - which cause IE to crash or, on IE8/9, will only work while the Dev tools console window (F12) is open.

What I am looking for is either:

  • a library that emulates console.log on IE6/7/8/9 so it doesn't crash everything when something tries console.log()
  • a way to guard against this error.
Community
  • 1
  • 1
Goro
  • 9,919
  • 22
  • 74
  • 108
  • 2
    What libraries do you use that leave `console.log` calls in production code? You shouldn't be doing that either, which would solve the problem! – James Allardice Jun 27 '12 at 17:33
  • Just use `window.console && window.console.log('test')` everytime and there won't be any problem. – freakish Jun 27 '12 at 17:34
  • Best thing is to file bug reports with those libraries to remove them. They should not be in production code. – epascarello Jun 27 '12 at 17:34

0 Answers0