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
Post a Comment