I'm using Firebug and have some statements like:
console.log("...");
in my page. In IE8 (probably earlier versions too) I get script errors saying 'console' is undefined. I tried putting this at the top of my page:
<script type="text/javascript">
if (!console) console = {log: function() {}};
</script>
still I get the errors. Any way to get rid of the errors?
For debugging in IE, check out this log4javascript
Encountered similar problem running console.log in child windows in IE9, created by window.open function.
It seems that in this case console is defined only in parent window and is undefined in child windows until you refresh them. Same applies to children of child windows.
I deal with this issue by wrapping log in next function (below is fragment of module)
Sometimes console will work in IE8/9 but fail at other times. This erratic behaviour depends on whether you have developer tools open and is described in stackoverflow question Does IE9 support console.log, and is it a real function?
Noticed that OP is using Firebug with IE, so assume it's Firebug Lite. This is a funky situation as console gets defined in IE when the debugger window is opened, but what happens when Firebug is already running? Not sure, but perhaps the "firebugx.js" method might be a good way to test in this situation:
source:
https://code.google.com/p/fbug/source/browse/branches/firebug1.2/lite/firebugx.js?r=187
(updated links 12/2014)
I am only using console.log in my code. So I include a very short 2 liner