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 e 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
----------------- 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.
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 e 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./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.
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jul 16, 2010 at 14:07 user291701user291701 39.8k75 gold badges195 silver badges288 bronze badges 5- Are you viewing it in the same browser? – Nick Craver Commented Jul 16, 2010 at 14:10
- you get those errors in firefox?... or another borwser? – Guy Schaller Commented Jul 16, 2010 at 14:11
- I get the errors in firefox, same browser, just pushed it to my live site. – user291701 Commented Jul 16, 2010 at 14:12
- @user291701 - Are you using firebug or firebug light? – Nick Craver Commented Jul 16, 2010 at 14:13
- In the about, it just says "Firebug version 1.5.4". – user291701 Commented Jul 16, 2010 at 14:16
3 Answers
Reset to default 6The 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