Showing posts with label internet explorer. Show all posts
Showing posts with label internet explorer. Show all posts

Friday, July 11, 2014

console.log throws error on Internet Explorer IE

console.log is a great debugging tool. It is better than alerts.  Older versions of IE will give you a
'console' is undefined
Error if you try to use it. I put the following at the top of a javascript file that is included in my web app and it kept IE from throwing script errors.
//If we are on IE8 or similar console won't be defined
if (typeof console === 'undefined') { ////do an alert in IE. You could make it write to another window if that worked better
//console = { log: function () { alert(arguments[0]); } };
//just swallow the call in IE
console = { log: function () { } };
}
I crafted this solution from this page.