Console is undefined error in IE9

南楼画角 提交于 2019-12-29 05:07:25

问题


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.


回答1:


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(){}
  };
}



回答2:


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




回答3:


Do you have a console.log() or console.error() call in your code?



来源:https://stackoverflow.com/questions/10183440/console-is-undefined-error-in-ie9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!