Programming Tips - javaScript: How can I log in a way that works for all browsers?

Date: 2011may26 Platform: web Language: javaScript Warning: This is for older versions - now you can use console.log() Q. javaScript: How can I log in a way that works for all browsers? A. Firefox has dump() and IE has console.log() so make do this:
function debug(a) { if (a == null) return; if (a.indexOf('\n') < 0) a += '\n'; if (window.dump) { dump(a); // Firefox } else if (window.console && window.console.log) { window.console.log(a); // IE } } function exampleUse() { debug('testing'); }
More info http://www.davekb.com/search.php?target=Firefox+dump