Dave's Brain

Browse - programming tips - debug dump log for all browsers

Date: 2011may26
Platform: web

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
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: