A site that we were working on used javascript in several places to allow users to select a news feed to display on the page. In most browsers, the feeds always worked perfectly fine. But in Internet Explorer, sometimes they would stop functioning for no apparent reason. Other scripts on the page still worked- it was only this isolated feature that would break.
What was especially confusing was that, when I'd open IE's develop console and start debugging, the problem would fix itself. Strange. After quite a bit of searching, I found the source of the problem, and it wasn't at all what I expected. It had nothing to do with errors in our javascript, and everything to do with IE.
You see, in IE, javascript's console.log is only available after you have opened the Developer Tools. This can be problematic because if you leave calls to console.log in your Javascript, you will get an error in IE, but not necessarily in other browsers. This happens because there is no console object in the window name space. But, when you open the Developer Tools and start debugging, the console calls will work just fine.
What can be especially confusing is when you have only one call to console.log hidden away in your code that only gets called on certain conditions. Scripts before the call will run, but scripts after it won't because of the error. This is what was happening to me, and it led to me looking in all the wrong places to try to fix the problem before finding out what was really happening.
Fixing the problem is as simple as making sure you've commented out or removed all calls to console.log, but sometimes you want to keep them around for use in other browsers. Developers have come up with several javascript fixes to have the call fail gracefully. You can check out several of these solutions on this thread on Stack Overflow:
http://stackoverflow.com/questions/690251/what-happened-to-console-log-in-ie8
Dan Wilson has also posted a quick fix using jQuery:
http://www.nodans.com/index.cfm/2010/7/12/consolelog-throws-error-on-Internet-Explorer-IE
Hopefully this information will save you from hunting all over your code for syntax errors like I did.


follow us