views:

66

answers:

2

Hey everyone!

I just started doing some Javascript work for a project, I do mostly backend work so I'm sorry for being new at this! Also, not using a Javascript framework because I want to learn about the fundamentals before making everything very easy for myself :)

So, here is my question/confusion: I wrote a little javascript that dynamically changed forms. This is how I called the code:

// loads the initial box
window.onload = initList(environment_box);

// loads artifacts on each change to environment select box
environment_box.onchange = changeList;

This worked like magic - in CHROME that is! I never noticed it wasn't working in Firefox (its just an internal tool, so I can assume decent browsers, but I figure hey, if its working in Chrome, it will work in Firefox!). So, I did some investigation, and it seems as though the code isnt getting executed in Firefox. I whipped out firebug and wanted to see what was going on.

The interesting thing was, when I enabled Console on firebug, my code got executed! I am very confused as to why, and I would much appreciate any help I could get. Thanks!

-Shawn

+9  A: 

You are calling some method on console in your JavaScript is my best guess. Chrome has console defined be default, so it is not a problem.

On Firefox, however, there is no such global object (not without Firebug), so when you try to call a property on an undefined object like,

console.log(..);

it throws an exception which you are not catching, so the JavaScript execution halts.

Anurag
Wow. That could very will be it. A friend of mine just told me to use console.log because it was awesome, and it seemed so! I shall try this theory of yours right now!
shawnjan
You are the man ;)
shawnjan
I can't accept the answer for 4 minutes, but I will.
shawnjan
It's best to define it yourselves if it's not already available. Ideally you wouldn't want console.* in a production app, but then again it's easy to change the behavior of a custom object to start sending logs/errors to a remote server with the flip of a switch. So console logs are good, but have a backup plan embedded in your scripts, or just overwrite the whole thing and in development mode send it to the native console (if exists), or remote server for production.
Anurag
+1  A: 

You're probably calling a method of the console object which just doesn't exist by default in most web browsers. It may be always available on webkit based browsers (like Chrome) but with firefox/IE(/opera?) it requires an external add-on, either firebug or a javascript dependency.

Checkout things like firebugx which simply defines the most common methods of a console object as no-op functions.

Sebastien Tanguy