Resolved: Logging to Firebug console breaks IE

by jenny on 07 June 2008 - 05:05pm in

The firebug console is great for debugging javascript -- but it's really annoying when you want to quickly check something in IE and can't without first removing all your debug statements to avoid a bunch of javascript errors.

Here's a handy log function which checks first that firebug is in use before trying to log to the console. The function is a no-op in IE.

log_debug = function() {
  if(window.console && window.console.firebug) console.log.apply(this, arguments)

log_debug('foo', 'bar', 'bash')

+1 to you

+1 to you

How about

I use the following code:

if (console == null) console = { log: function () {
for (i in arguments) { alert(arguments[i]); }

For firefox if console is already declared then we use that, but in IE we create our own console.log function.

I suppose if you can stomach

I suppose if you can stomach a lot of alerts, that could work. ;)

I think these days IE has its own developer tools (possibly with its own console?)... wouldn't know as I don't work with it anymore.

IE Dev Tools

IE 8 and 9 have their own dev tools module. I only noticed this issue when running scripts on pages before loading up the dev tools package in IE. Makes sense that the console object wouldn't be initialized until then, so for now this will have to do :P Firefox and Chrome usually never have a problem, but I guess it's because they probably initialize a console object for each window/tab.