2

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

marc40000
  • 3,167
  • 9
  • 41
  • 63
  • Firebug will be your best friend and is good at this. Make sure you're stepping into function calls, and not over them. But you should still see errors. We can be your friends to... if you post the code ;) – Matt Jul 25 '10 at 21:18
  • The (Google) Chrome Developer Tools are also handy. You might see if you get any warnings or issues using those, they may help you fix it in Firefox. – Joshua Enfield Jul 25 '10 at 21:20
  • If your code works in IE but not other browsers, your code is wrong :D (God I hate IE!!!) – Thomas Eding Jul 26 '10 at 01:01
  • @trinithis, that's just dumb, back when I wrote that code, firefox, chrome, safari etc. didn't even existed! – marc40000 Jul 27 '10 at 14:31

3 Answers3

3

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.

Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
  • 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 Neverdal Jul 25 '10 at 21:24
2

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

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

Chris O
  • 5,017
  • 3
  • 35
  • 42
  • 2
    Something ("I tried stepping through the javascript Firebug"), makes me think he knows about Firebug. – Matt Jul 25 '10 at 21:19
  • @Matt, yes I totally concur, perhaps if I read the entire question, I might have gleaned that useful bit o' info ;-) – Chris O Jul 25 '10 at 21:20
2

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
  • 687,336
  • 108
  • 737
  • 1,005
  • 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 Jul 26 '10 at 00:58