Visit Sponsor

Written by 8:12 am Javascript

console.log throws error on Internet Explorer IE

If you have calls to console.log in your Javascript, you will get an error in Internet Explorer. This is because there is no console variable (object) in the window name space.

Sure you could take out all your console.log statements, but usually you need those around for a little while. Here is a quick snippet you can use in JQuery that’ll take the place of console.log. Your Firefox console will still work and you won’t get errors on Internet Explorer.


jQuery.logThis = function( text ){
if( (window['console'] !== undefined) ){
console.log( text );
}
}

Now when you want to log something, you can use:


JQuery.logThis( "I pity the fool who uses console.log() ");
$.logThis( "I pity the fool who uses Internet Explorer");

Happy Days are here again!

Visited 33,211 times, 1 visit(s) today
[mc4wp_form id="5878"]
Close