29 December, 2006

workaround to make firebug console.log function bug free on IE

Firebug is very usefull for web development but its console only works great on Firefox for now.
If you want to keep console.log calls in your app event when your app is used on Firefox without the Firebug plug-in or on IE, you can add this line at the very first start of your JS code :

try { console.log('init console... done'); } catch(e) { console = { log: function() {} } }

This code tries to write some text in the Firebug console. If it fails (no Firebug plug in installed or under IE), it instantiate an object called 'console' that has a method called 'log' that does nothing !