使用带有firebug的console.log()可以在本地使用,但在发布到我的实时站点时则不行 [英] Using console.log() with firebug works locally, but not when published to my live site

查看:78
本文介绍了使用带有firebug的console.log()可以在本地使用,但在发布到我的实时站点时则不行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:

console.log()

在处理我的webapp时将消息记录到firefox(3.6.6)/ firebug的方法。当我在本地查看应用程序时,它工作正常,日志消息就可以了。当我将我的应用程序推送到我的实时服务器并查看页面时,我得到了很多控制台未定义错误。

method to log messages to firefox (3.6.6)/firebug while working on my webapp. When I view the app locally, it works fine, log messages come up ok. When I push my app up to my live server and view the page, I get lots of 'console not defined' errors.

我不太确定控制台对象是怎样的甚至在第一时间解决了,因为我首先没有任何js包含它。使用控制台对象的正确方法是什么?

I am not quite certain how the console object was even resolved in the first place, since I don't have any js includes for it in the first place. What's the right way to use the console object?

谢谢

http://getfirebug.com/logging

--------- --------编辑----------------------------

----------------- Edit ----------------------------

是的我使用相同的浏览器(FF) - 我只是将项目推送到现场主机,我只在那里得到错误。但有些奇怪的是,现在有些控制台语句正在运行,其他语句仍然会出错。复制粘贴在这里作为完整性检查:

Yeah I am using the same browser (FF) - I just pushed the project to the live host, and I only get the errors there. What's strange though is that some of the console statements are working now, others just still give the error. Copy-pasting here as a sanity check:


控制台未定义
[中断此错误] console.log(窗口) 。地点);

console is not defined [Break on this error] console.log(window.location);

控制台未定义
[中断此错误] console.log(farmAttrAsJson);

console is not defined [Break on this error] console.log(farmAttrAsJson);

单击按钮时会记录上面的第二个语句。所以我第一次点击,得到了那个错误。等了几分钟,再次点击,然后记录好了。

the second statement above is logged when clicking a button. So the first time I clicked, got that error. Waited a few minutes, clicked again, and then it logged ok.

推荐答案

除非Firebug已打开,否则未在FF中定义控制台对象。

The console object is not defined in FF unless Firebug is open.

在Chrome中,它始终是定义的。

In Chrome it's always defined.

处理它的一种方法是定义它,如果它没有定义:

One way to handle it is to define it if it is not defined:

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

这篇关于使用带有firebug的console.log()可以在本地使用,但在发布到我的实时站点时则不行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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