views:

53

answers:

3

Hi !

I have some old javascript code from around 2000-2002 which (surprisingly) still works in IE, but doesn't in Firefox, Chrome, Opera etc. I already found out about some quirks, some browsers do some things this way, some another. So there are code snippets on the internet to create some browser plattform independent function that does it.

Now my problem is, to even locate the problems. Right now, there are buttons in the website, when I click them, something happens in IE, but Firefox does just nothing. There isn't even an errormsg. I tried stepping through the javascript Firebug, but at some point in the code, when I do the next debug step, the script just seems to abort, without any error message. It doesn't continue with the next statement. Pretty strange and I have no idea what causes it or how to fix it. :/

So how do I debug javascript so I get error messages telling me what the problem is, for example, what function/variable I'm using isn't defined in firefox or when I use wrong parameters.

Thx & Best regards Marc

+2  A: 

There's FireBug, but it only works for Firefox.

EDIT: Doh, you already mentioned this in your question.

Chris O
Something ("I tried stepping through the javascript Firebug"), makes me think he knows about Firebug.
Matt
@Matt, yes I totally concur, perhaps if I read the entire question, I might have gleaned that useful bit o' info ;-)
Chris O
+2  A: 

Firebug for firefox is okay. The console for safari and chrome, IMO, is better. In either case, right click the page, hit "inspect element," and click the "console" tab in the pane that pops up. Now you'll see any errors and warnings generated by the page.

If you really want to debug the scripts you can click on the "Scripts" tab and either pause execution immediately or set a break point. Then, you can step through the execution of the script line by line, inspecting the call stack and watch list as you go.

no
Small suggestion with the Chrome console: Splitting your code into files, just like you would with a regular application, makes testing and debugging faster and easier. The console will obviously show the file name where the error happened, which should makes life a bit easier.
Christian Jonassen
+1  A: 

Firefox doesn't popup error messages or put them in the status bar (like IE). You have to open the Error Console to see the errors.

Firefox puts Javascript errors in the Error Console, but also HTML and CSS errors and warnings.

As to what might not work in the code, there are plenty of things that are IE specific and won't work in any other browser. Also there is a big difference between IE in quirks mode and IE in standards compliant mode. Put a proper doctype in the page so that it's rendered in standards compliant mode, which will make IE more like other browsers, and some IE-specific quirks are removed. This might cause your old script to stop working, in which case you know that it's likely that it's some IE-specific feature that causes the problem.

Guffa
The error console is very helpful. I still had one problem where it didn't work and nothing showed up in it, but everything else the console showed either helped fixing the issue directly or hinted into something I could google. :)
marc40000