Firebug

How to surpress Firebug console on non-firefox browsers.

March 18th, 2008  |  Published in Firebug, Javascript

Firebug is the most useful Javascript debugging tool out there. Occasionally when doing a large piece of Javascript development I tend to use the console utility which cause other browsers (such as IE) to crash your script. So here is a small piece of code that I have found to be extremely useful in making other browsers immune to the errors. Simply add this at the start of your script and let the magic begin!

if (!("console" in window) || !("firebug" in console)) {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
			"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	window.console = {};
	for (var i = 0; i < names.length; ++i) {
		window.console[names[i]] = function() {};
	}
}

I will be posting more Javascript tips in coming days.