Avoid using console.log in Internet Explorer!

Subtitle “at least when releasing production code“. I also considered naming this post “Another reason why I’m really going to miss Flash“.

A funny thing happened to me on the way to testing browser compatibility today. My javascript seemed to completely disappear on me when running in IE9. So I popped open the developer tool console in IE9 and suddenly… *poof*…. my code was working correctly. I shrugged it off as a fluke after looking at it closely.

I went back to finishing up the code and then went back to give it one last pass. And again, code was completely non-functioning in Internet Explorer, that is, until I opened up the dev tools.

At that point I had to investigate further (i.e. google), and here are the stunning findings courtesy of T.J. Crowder on StackOverflow:

On IE8 and IE9, the console object doesn’t exist until/unless the developer tools are open. Strange but true.

You should be getting script errors along the lines of “console is undefined” when you don’t have the dev tools open.

Well now I know better.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>