Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console is undefined error in IE9

I have a graphics page which shows SVG graphics. I am using Raphael graphics framework. The page displays properly in Firefox, Also if the F12 developer tools is set 'on' in IE9 it works fine. The map show partial data (its a node link diagram and it shows only one child node out of 12 nodes) in IE9 if the F12 developer mode is set off and application is started with browser cache cleared (simulating a general user).

Update: I kept the Debugger on and Shows me the error "Console is undefined". So I think its not a graphics rendering issue, and also I am not using the console explicitly, maybe the mindmap js is using it internally, but how to again get rid of this issue?

Update: I found the issue and commented out the console.log entries from the js files.

Thanks.

like image 356
pri_dev Avatar asked Apr 17 '12 00:04

pri_dev


People also ask

Why does Javascript console say undefined?

A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .


2 Answers

Probably your code or the code you are calling is using console.log or something like it.

You could add this code in the global scope to create a dummy wrapper for IE (or any browser that doesn't support it). Just put the following code somewhere before you call any other libraries:

if(!(window.console && console.log)) {
  console = {
    log: function(){},
    debug: function(){},
    info: function(){},
    warn: function(){},
    error: function(){}
  };
}
like image 111
Kip Avatar answered Nov 15 '22 05:11

Kip


The problem is that your js code calls sometime a console method, for example 'console.log', but your browser does not have console (or has it closed);

To fix this, add this (once) before including any of your scripts:

//Ensures there will be no 'console is undefined' errors
window.console = window.console || (function(){
    var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function(){};
    return c;
})();

This will create a 'pseudo' console only if it doesn't exist, so that 'console is undefined' error will go away.

Hope this helps. Cheers

like image 33
Edgar Villegas Alvarado Avatar answered Nov 15 '22 05:11

Edgar Villegas Alvarado