IE控制台问题 [英] IE console issues

查看:107
本文介绍了IE控制台问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了我的index.php并删除了所有的console.log(),但是当我转到IE7时,我仍然遇到控制台错误。有趣的是,如果我检查IE9,然后将浏览器模式更改为IE7,它工作正常,但如果测试网站直接进入IE7浏览器,它会给出一个控制台错误消息。

I checked my index.php and removed all the console.log() but when I go to IE7 I am still getting console errors. The funny thing is if I check the in IE9 and then change the browser mode to IE7 it works fine, however if test the site straight into an IE7 browser it gives a console error message.

有关如何制止此事的任何想法吗?

Any idea on how to stop this please?

推荐答案

您可能错过了某个地方的 console.log 来电。它在IE9中切换到IE7的原因是,只要打开控制台切换版本,就会创建控制台对象。因此,在IE9的IE7仿真模式中不会抛出任何错误。

You probably missed a console.log call somewhere. The reason why it works in IE9 switching to IE7 is that the console object is created as soon as you open the console to switch the version. Thus no error will be thrown in the IE7 emulation mode of IE9.

更好的解决方案是事先在js-code中包含以下内容:

The better solution is to include the following in your js-code beforehand:

if (!window.console){console = {log:function(){}};}

现在所有的 console.log 调用都不会抛出错误,但会被忽略。

Now all your console.log calls won't throw an error but will be silently ignored.

我在开发时执行以下操作:

I do the following when developing:

var logging = 1;
if (!window.console){console = {log:function(){}};}
function _log(a) { if(logging) { console.log(a); } }

继续使用 _log(foo)代表整个代码。现在,您可以使用简单的 logging = 0 切换日志记录,并且可以安全地防止丢失的控制台对象。

and keep on using _log("foo") for the entire code. Now you can switch logging with a simple logging = 0 and are safe against the missing console object.

这篇关于IE控制台问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆