17 May 2013

IE9 and console.log problems

Hello everyone,

I have found that Internet Explorer 9 has some problems when you want to use console.log in your sites.
If you have for example:

Code:
console.log('www.extremedev.blogspot.com');

then in IE9 without the Developer Tools open it will throw an exception (but you will not be able to see it because the Developer tools is not opened).
This happens because IE does not find the console object.

There is a small fix for this - you have to
put in a common javascript file an override for console if it doesn't exist. Here is the "magic" code:

Code:
 // IE 9 fix for console object
if (!window.console) window.console = {};
if (!window.console.log) window.console.log = function () { };

Good luck.

No comments:

Post a Comment

your thoughts are welcome:

Need more? Leave comments and subscribe to my blog.

.