Dave's Brain

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

Date: 2011may26
Platform: web
Warning: this is for older versions - now you can use console.log() 

Q.  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

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.