Preventing calls to console.log throwing errors in IE
When developing applications which make a lot of use of Javascript, it can be very useful to use the console.log() function to output debug to Firefox’s Firebug console or to Chrome’s Javascript console.
However, such calls will cause errors when run inside IE as it does not by default have a console object (depending on the version of IE you are running and what add-ons you have installed). These errors may prevent other aspects of your Javascript from running, essentially breaking you application.
One quick solution to this is to add the following piece of jQuery to your code which will prevent console.log() from doing anything at all in IE and hence preventing the errors from occurring:
$(document).ready(function(){
if ($.browser.msie) {console = { log: function() {} }};
})
Alternatively, you can incorporate the following piece of code which will, in IE, cause all messages sent to the console via console.log() to be alerted using alert() instead:
$(document).ready(function(){
if ($.browser.msie) {console = { log: function(msg) {alert(‘Debug: ‘+msg);} }};
})