Debugging Javascript on IE

Everyone should know about Firebug for Mozilla by now. I had the problem not being able to use ‘console.log()’ on IE.

Here’s a quick solution, a wonderful package log4javascript by Tim Down.

I used wrapper class to switch between the two on different browsers.

if(navigator.userAgent.indexOf("Firefox") == -1) {
// Create the logger. "mylogger" is the unique name of the logger and
// can be any string.
var log = log4javascript.getLogger("mylogger");// Create a PopUpAppender with default options
var popUpAppender = new log4javascript.PopUpAppender();

// Change the desired configuration options
popUpAppender.setFocusPopUp(true);
popUpAppender.setNewestMessageAtTop(true);

// Add the appender to the logger
log.addAppender(popUpAppender);

var console = Class.create();
console.log = function(s) { log.debug(s);  }
console.debug = function(s) { log.debug(s);  }
console.info = function(s) { log.info(s);  }
console.warn = function(s) { log.warn(s);  }
console.error = function(s) { log.error(s);  }
}
Advertisement

2 thoughts on “Debugging Javascript on IE

  1. Version 1.3 of log4javascript released last week has explicit support for Firebug as part of the BrowserConsoleAppender. It also now allows you to log objects, which lets you take advantage of Firebug’s object inspection.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s