I remember the day I learned that I could use console.log to test my app instead of having to alert everything. Man did I feel good and smart. Everything was very smooth, and fast. No longer did I have to close every single alert in order to get to the next one, nor did I had to worry about leaving some rouge alert saying You made it into the if!
But then again every time I tried to test in IE beauty became the beast. Instead of getting a good log in the IE console which… ooops doesnt exist, I got a nasty js error saing what the hell is console.log ?
So I got into the habit of cleaning up my console.logs after using them which really didn’t help me testing out something in staging or dev because when you are making heavy client side apps, everything is ajax based, and you always need to know if you are showing the exact data that you received or if your js code is doing something funky.
Solution simply use another function that checks if console.log exists and if so log it, else don’t
function cLog( text ){
if( (window['console'] !== undefined) ){
console.log( text );
}
}
Updated with a better solution
if(!this.console){
window.console={
log:function(){}
};
}
Enjoy!
Would it work in IE to use a div as a fake console log?
function cLog( text ){
if( (window['console'] !== undefined) ){
console.log( text );
} else {
$(‘#console_log’).append(text + ”)
}
}
Great idea Alex!
I guess you could put and absolute positioned element at the bottom of the screen to simulate as much as possible a typical console.log
Then all you have to do is remove it from the DOM once you are finished. jQuery shouldn’t fire an error if the DOM element does not exist I believe.
Or if we are already removing the div might as well remove the DOM console.log to I guess. But yeah this should work.
You know you’ve made it what your solutions pop up when i google search errors. Nice work huevos
Hey keith! thanks for the good vibes =)
Works Beautifully! Just read this post, in middle of a project, and was facing this problem.
Hey Rupin! Nice to hear from you man. Glad it helped you out. Hope things go great with your project.