Wednesday, January 14, 2009

How to surpress Firebug console on non-firefox browsers.

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 extremely useful code 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() {}; } }

http://blog.deensoft.com/category/firebug/

No comments: