måndag 26 augusti 2013

Javascript and console

To write info to the console when you are working with javascript is a nice way to avoid a ton of alerts, however this way of keeping track of things have a slight downside

This downside is that in some browsers the console isn't available. In this case I discovered the problem with IE9. I had a javscript which was using console.info("Some interesting info") to keep track of things that was happening in a function. The "funny" thing was that in the production environment I was accessing the CRM from my own machine running IE10 or Firefox 22 which wasn't giving me any problems, everything was working peachy. However, in my development environment I was using IE9 and in that case you need to have the developer tools open (press F12) otherwise there is no console available and the javascript crashes, silently.

The easy solution is to have an if-clause saying "if (window.console) console.info..." that checks if there's an available console to put stuff in.

Rickard Norström
Developer at CRM-Konsulterna