Social Icons

Pages

Solving javascript console.log issue in IE



I recently run into strange issue. My interface work perfectly for all browsers except IE. My code was IE compatible and IE debugger did not show any errors, moreover when i enable the IE debugger everything works?!?! I thought world must hate me.
So i started asking questions myself and after hours of Microsoft swearing, changes and blind testing (could not use IE debugger) found all answers. Issue was related with console.log calls.

Why when i turn on IE debugger tools with F12 and refresh the page evryhting works?

In that case  "console" object exists in the the window name space

Ok so if i disable console.log then my interface will work on IE, but i really need to use console.log? 

Sure you could take out all your console.log statements, but usually you need those around for a little while.
You put this very simple snippet before all your console calls:
if (!window.console) console = {log: function() {}};
Thus your Firefox/Chrome console will still work and you won't get errors on Internet Explorer. With above for browsers which do not support console you create such a object so when you call it somewhere in your code browser will not complain.
Another JS mystery down..

Няма коментари:

Публикуване на коментар