- Project tools
-
-
- How do I...
-
| Category |
Featured projects |
| scm |
Subversion,
Subclipse,
TortoiseSVN,
RapidSVN
|
| issuetrack |
Scarab |
| requirements |
xmlbasedsrs |
| design |
ArgoUML |
| techcomm |
SubEtha,
eyebrowse,
midgard,
cowiki |
| construction |
antelope,
scons,
frameworx,
build-interceptor,
propel,
phing
|
| testing |
maxq,
aut
|
| deployment |
current |
| process |
ReadySET |
| libraries |
GEF,
Axion,
Style,
SSTree
|
| Over 500 more tools... |
|
Debugging
JavaScript:
Notes
and Tips
Saturday, January 14, 2006
Christopher M. Balz
First, be prepared
to check non-JavaScript areas that could be affecting your
JavaScript:
Ensure you are
running from a ‘http://’-type url.
Ensure you are
running the latest copy of your web page and all related files.
Hold down the
shift key while clicking the ‘refresh’ button on the
web browser.
<Shift>-<Cntrl>-R
is the keybinding for this.
This bypasses
any caching mechanism that may not be working properly.
If you still
suspect a caching problem on Internet Explorer (and it is a very
rare but known issue on Internet Explorer 6):
Tools ->
Internet Options -> Delete Files -> “Yes” to
delete all offline content.
Tools ->
Internet Options -> Delete Cookies
Tools ->
Internet Options -> Clear History
Tools ->
Internet Options -> Settings -> “Check for new
versions of stored pages” -> “Every time”.
Click the “OK”
option to exit the Internet Options dialog.
If you suspect
the root of the problem is with the html as it is originally
downloaded by the web browser, use the view source option.
Firefox: View ->
Page Source
Internet
Explorer: View -> Source
If you suspect
the root of the problem is with the html as it is currently resting
on the page, use the “View Rendered Source” tool
(Firefox
tool; Internet
Explorer tool).
If you suspect a
problem with the css files used, take the urls used in the ‘link’
tags in the html source (“view source”, above) and
paste them into the web address bar of your web browser.
Examine the file
for any evident problems.
If you need to
examine the http header request, use the free LiveHTTPHeaders
tool with Firefox.
It is also
possible to purchase a useful tool such as HttpWatch
for Internet Explorer.
If you suspect a
problem with the JavaScript:
If you are using
Firefox or Mozilla, ensure that you have the JavaScript Console
open.
Tools ->
JavaScript Console
If you are using
Internet Explorer, ensure that you have the JavaScript debugging
option turned on.
To ensure that
this setting is turned on, go to:
Tools ->
Internet Options -> Advanced
Ensure that
‘Disable Script Debugging’ option or options are not
checked.
Ensure that
‘Display a notification about every script error” is
checked.
Sometimes,
Internet Explorer loses this setting on its own, and must be
reset.
At first, it is
usually easier to use a quick ‘alert’ statement rather
than opening up a debugging session.
If a debugging
session is needed, choose one of the two available debuggers,
Visual
Studio (the free Web Developer edition is
recommended) or Venkman.
Visual Studio:
It must be
installed on your system.
It only works
with Internet Explorer.
To open it up,
either:
Reload the
page, if it shows a JavaScript error on it and you want to break
into the debugging session at that error.
Insert a
breakpoint in the JavaScript code by typing in the statement
“debugger;” where you want the breakpoint.
Reload the
page.
(Used less
often): Type ‘javascript: debugger;’ in the web
address bar.
Follow the
defaults in the dialogs that appear.
Make sure you
can see all the running documents:
Debug ->
Windows -> Running Documents.
View them by
clicking on their name in the Running Documents pane.
Make sure that
you can see the ‘Watch’ and ‘Call Stack’
window panes.
Select them
from Debug -> Windows
Make use of:
Debug ->
Step Into
Debug ->
Step Over
Debug ->
Step Out.
To continue
running the currently loaded web page with the debugger session
still running:
Debug ->
Continue
To close the
debugger without closing the web browser window that is associated
with the debugging session:
Debug ->
Detach All
File -> Exit
“No”
on save changes
Venkman
It must be
installed into your version of Firefox or Mozilla.
Firefox is
recommended over Mozilla.
Both are from
the same organization.
Mozilla is
currently deprecated for all but corporate installations where a
complete, integrated browser/e-mail/etc. solution is required.
On Firefox, go
to Tools -> JavaScript Debugger.
Click on the
“Open Windows” tab near the upper left section of the
window.
Select the
browser window that holds you’re the page that you would
like to debug.
Right-click
and select “Set as Evaluation Object”.
To get the
debugger to enter your code:
Reload the
page, if it shows a JavaScript error on it and you want to break
into the debugging session at that error.
Insert a
breakpoint in the JavaScript code by typing in the statement
clicking in the left margin of the file as displayed in the
Venkman debugger. Click where you want the breakpoint.
Reload the
page.
The major
controls and window panes are much easier to find than on Visual
Studio, so there is no need to enumerate them here.
Good luck with your
debugging! May it be short. ;)
|