Most modern browsers define the console.log function. How about instead of writing your own error handler, you go ahead and call console.log wherever there is an error. Then for browsers that do not define console.log, you can define it yourself, using whatever you want. For example, if you want to warn about an error in IE (or FF without firebug installed, etc.), you can use this code:
<html> <head> <title>Test</title> </head> <body> <button onclick="throwError()"> Throw Error</button> <script type="text/javascript"> function throwError() { console.log("error here!"); } if (!window.console) { window.console = { log: function(e) { alert(e); } }; } </script> </body> </html>
You can add whatever you want to the console object. I tested this in IE8 and Firefox, and I'm sure you can make this idea work for any set of browsers that you support.
EDIT: Looks like you can also overwrite the default console.log function in Firefox, Safari, and Chrome. Just reassign the console item's log item to a new function that does everything you want during production.
source share