Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which browsers support console.log()?

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"); 
like image 371
KingKongFrog Avatar asked Dec 29 '12 23:12

KingKongFrog


People also ask

How do I use the console log in browser?

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".

Can you use console log HTML?

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.

Does console log work in IE?

console. log() only works when IE's dev tool is open (yes IE is crappy). see stackoverflow.com/questions/7742781/…


2 Answers

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.

like image 164
Aaron McIver Avatar answered Oct 14 '22 15:10

Aaron McIver


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/

like image 23
Madbreaks Avatar answered Oct 14 '22 13:10

Madbreaks