javascript IE10 console.log 不工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14695422/
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 22:20:12  来源:igfitidea点击:

IE10 console.log not working

javascriptinternet-explorer

提问by James

I just started playing around with IE10 on Win8 and ran into problem. The developer tools console doesn't seem to work when the Document Mode is set to Standards. I've played around with both the Browser Mode and the Document Mode, and console works when Set as IE9 Standards, but setting it to simply "Standards", the default for IE10, console is undefined. Any ideas?

我刚开始在 Win8 上玩 IE10 并遇到问题。当文档模式设置为标准时,开发人员工具控制台似乎不起作用。我玩过浏览器模式和文档模式,当设置为 IE9 标准时,控制台工作,但将其设置为简单的“标准”,IE10 的默认值,控制台未定义。有任何想法吗?

This is not a duplicate. When testing, developer console is open. Switching Doc mode to IE9 standards and reloading displays console output as expected. Switching back to IE10 standards displays no console output. Debugging shows console is undefined which thus sets console.log to an empty function to handle the undefined. I'm curious as to why the console is undefined when in IE10 standards mode.

这不是重复的。测试时,开发者控制台是打开的。将 Doc 模式切换到 IE9 标准并重新加载会按预期显示控制台输出。切换回 IE10 标准不会显示控制台输出。调试显示控制台未定义,因此将 console.log 设置为一个空函数来处理未定义的。我很好奇为什么在 IE10 标准模式下控制台未定义。

I'm running Win8 in a VirtualBox. My page is HTML4 markup with appropriate doctype.

我在 VirtualBox 中运行 Win8。我的页面是具有适当文档类型的 HTML4 标记。

回答by Andrew

The reason why console.log();is undefined is because that's how standards mode works. IE 8 has a compatibility mode that literally turns it into IE 7, removing all understanding of features added to IE 8. The console was added in IE 10, so by running it in standards mode, it would make sense for it to throw errors.

console.log();未定义的原因是因为这就是标准模式的工作方式。IE 8 有一个兼容模式,从字面上把它变成了 IE 7,消除了对添加到 IE 8 的功能的所有理解。控制台是在 IE 10 中添加的,所以通过在标准模式下运行它,它会抛出错误。

<head>
    <title>Force IE 10</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>

This meta tag up here will force IE to run in the most recent version you have installed (disabling standards and compatibility mode). This is the only way to have your console defined in IE 10 in standards mode — by disabling standards mode.

此处的元标记将强制 IE 在您安装的最新版本中运行(禁用标准和兼容模式)。这是在标准模式下在 IE 10 中定义控制台的唯一方法 - 通过禁用标准模式。

回答by left

define it!

定义它!

if (typeof console == "undefined") {
    this.console = {log: function() {}};
}

see : 'console' is undefined error for Internet Explorer

请参阅:“控制台”是 Internet Explorer 的未定义错误