Write to the Javascript console Tag(s): Varia


Modern browsers provides a console to see javascript debugging output.

To print to the console, use :

console.log('Hello from Real\'s HowTo!');
Then if you activate the console (IE : F12, Firefox : Web development - Console, Chrome : Tools - Console), you see the output.

With IE, if the console is not active, an error occurs.

You can detect if the console exists, if not then you defined the console object with an empty log function.

if (!window.console) console = {log: function() {}};
Open your console (you may need to reload the page), and check the output!
blog comments powered by Disqus