开发者

Using console.log() with firebug works locally, but not when published to my live site

开发者 https://www.devze.com 2023-01-07 09:58 出处:网络
I\'m using the: console.log() 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

I'm using the:

console.log()

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.

开发者_运维百科

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?

Thanks

http://getfirebug.com/logging

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

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 is not defined [Break on this error] console.log(window.location);

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.


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

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


i found this one which looks even better because it has all the console methods. not just log

(function(){
   if (!window.console||!console.firebug){
  var methods = [
     "log", "debug", "info", "warn", "error", "assert",
     "dir", "dirxml", "group", "groupEnd", "time", "timeEnd",
     "count", "trace", "profile", "profileEnd"
  ];
  window.console = {};
  for (var i=0; i<methods.length; i++){
     window.console[methods[i]] = function(){};
  }
  }
  })();


You can no longer detect for Firebug using !console.firebug.

"The console API formerly implemented a console.firebug property. This property was removed from the API in Firebug 1.9.0 in order to prevent sites from detecting whether a user has Firebug installed."

Console API help on Firebug wiki

0

精彩评论

暂无评论...
验证码 换一张
取 消