[thelist] Debugging JavaScript in IE
George Dillon
George Dillon" <george.dillon at ukonline.co.uk
Thu, 23 Dec 1999 17:19:09 -0000
> Microsoft's script debugger ... I personally hate it, but it always
> shows you the line where the error occurred in the source
Jeremy - What are you on? :-) I recently asked if anyone can or does
use this or Netscape's version... I took the lack of replies to mean
nobody does. Are you saying you do, but don't like it?
Scott's dead right - turn on your debug messages, but don't expect
too much accuracy... the line references given by both IE and NN's
error alerts are only rough estimates. Something to do with the
discrepancy between your scripted pages and the compiler/browser
interpreted version. (I'm sure Jeff could/will explain it better ;-)
If they say the error is in line 340 (e.g.), then start looking from line
300. If you're using document.write though, you might as well forget
any line references, as they'll all be totally #@*&#ed!
Yes, go see Jeff's article to see how to turn it on and let's all nag Jeff
to take us to the next level soon.
When I screw up in JavaScript, I bung in loads of alert messages to
stagger through the process. That way I can usually narrow down the
location of the error and also keep a track on variables. (Sorry if this
is a bit vague, but it's X-mas and I've been hitting the Port). For e.g.
at the beginning of every major function you could add:
alert("function NAME starting")
or at crucial points you could use numbered alerts:
alert("alert# - namedvariable = " + namedvariable)
Then observe, or make a note of each alert as it comes, until the thing
breaks and then you'll know where the roblem is (and maybe what value
is causing the problem).
I recently advised using status-line messages instead (see tip harvest),
but for beginners I'd advise alerts - just don't forget to remove them or
comment them out when you're done.
Good Luck
George Dillon