Do all browsers support this? I would like to output an error using console.log()
but was wondering if this supported by all browsers?
console.log("Error etc");
Steps to Open the Console Log in Google Chrome With the Chrome browser open, right-click anywhere in the browser window and select Inspect from the pop-up menu. By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements".
The console. log() method in HTML is used for writing a message in the console. It indicates an important message during testing of any program. The message is sent as a parameter to the console.
console. log() only works when IE's dev tool is open (yes IE is crappy). see stackoverflow.com/questions/7742781/…
No, not all browsers support console.log
as it is not part of the standard and is an extension of the DOM and thus you should not count on its presence. To make your code resilient you should assume it does not exist and code accordingly.
I've done something like this in the past:
// Log to native console if possible, alert otherwise window.console = typeof window.console === 'undefined' ? {log:function(/* polymorphic */){alert(arguments)}} : window.console;
You can put that at the "top" of your JS and it works pretty nicely when you're forced to do debugging w/ a browser that doesn't support console
, and doesn't require you to change your other JS source that's already calling console.log
all over the place. Of course you might want to do something other than alert
to preserve your sanity...
http://jsfiddle.net/4dty5/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With