javascript - 'console' is undefined error for Internet Explorer -


i'm using firebug , have statements like:

console.log("..."); 

in page. in ie8 (probably earlier versions too) script errors saying 'console' undefined. tried putting @ top of page:

<script type="text/javascript">     if (!console) console = {log: function() {}}; </script> 

still errors. way rid of errors?

try

if (!window.console) console = ... 

an undefined variable cannot referred directly. however, global variables attributes of same name of global context (window in case of browsers), , accessing undefined attribute fine.

or use if (typeof console === 'undefined') console = ... if want avoid magic variable window, see @tim down's answer.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -