javascript IE9 中的控制台未定义错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10183440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:56:30  来源:igfitidea点击:

Console is undefined error in IE9

javascriptconsoleinternet-explorer-9

提问by pri_dev

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

我有一个显示 SVG 图形的图形页面。我正在使用 Raphael 图形框架。该页面在 Firefox 中正确显示,此外,如果 F12 开发人员工具在 IE9 中设置为“开启”,则它工作正常。该图显示IE9中部分数据(它是一个节点链接图,仅显示12个节点中的一个子节点),如果F12开发者模式被开启,并且应用程序在浏览器缓存被清除的情况下启动(模拟普通用户)。

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?

更新:我保持​​调试器打开并向我显示错误“控制台未定义”。所以我认为这不是图形渲染问题,而且我没有明确使用控制台,也许思维导图 js 正在内部使用它,但是如何再次摆脱这个问题?

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

更新:我发现了这个问题并从 js 文件中注释掉了 console.log 条目。

Thanks.

谢谢。

回答by Kip

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

可能您的代码或您正在调用的代码正在使用console.log或类似的东西。

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:

您可以在全局范围内添加此代码,为 IE(或任何不支持它的浏览器)创建一个虚拟包装器。在调用任何其他库之前,只需将以下代码放在某处:

if(!(window.console && console.log)) {
  console = {
    log: function(){},
    debug: function(){},
    info: function(){},
    warn: function(){},
    error: function(){}
  };
}

回答by Edgar Villegas Alvarado

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);

问题是您的 js 代码有时会调用控制台方法,例如“console.log”,但您的浏览器没有控制台(或已关闭);

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

希望这可以帮助。干杯

回答by Richard Connamacher

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

您的代码中有 console.log() 或 console.error() 调用吗?