Hack 39. Debug Scripting Code
great IDE, it's a great debugger for all sorts of
Windows programming tasks. You can even use it to debug VBScript or
JavaScript as it runs inside your web browser.I spent a lot of time writing web
applications without the benefit of Visual Studio. Before ASP.NET, I
would usually use a web tool like HomeSite to write web applications.
When ASP.NET came out and I started using Visual Studio, I got very
spoiled using the debugging capability of Visual Studio for my
ASP.NET code, but I always wished I could do the same for JavaScript
or VBScript. Thankfully, Visual Studio provides this exact
functionality. This hack details how you can set up Visual Studio to
debug
VBScript and JavaScript while it runs in
your browser.The first thing you have to do to enable debug scripting is to enable
script debugging in Internet Explorer 6:Open Internet Explorer.Navigate to Tools
(Internet Explorer)".
Figure 5-18. Internet Options dialogAdvanced tab

Internet Explorer.
|
script in a number of different ways. The first option is two menu
items that are available in Internet Explorer under the View
and you will then be able to jump into the debugger and place
breakpoints in your document. The second option is Break at Next
Statement, which will cause Internet Explorer to break into the
debugger whenever the next piece of script is run.You can also debug from inside Visual Studio. Open your Web Project
in Visual Studio and start the debugger. (You can start the debugger
using the Play button, which will launch a new browser, or you can
attach to an already existing Internet Explorer instance
[Hack #41] .) Once the
debugger is started, you need to access the
Running Documents window. This can be
done through the Debug
Documents or by using the shortcut key Ctrl-Alt-N
(Debug.RunningDocuments).The Running Documents window shows a list of all the currently
running web documentsusually this contains only a single
document. (In the case of frames or iframes, more than one document
can show up here.) The Running Documents window is shown in Figure 5-19.
Figure 5-19. Running Documents window

debugthe rendered HTML output of that document will be shown
as a normal HTML file. You will then be able to
set breakpoints and step
through client-side script just as if it were
any other code file, as shown in Figure 5-20.
Figure 5-20. Debugging client-side script

Windows client brethren, and this means more and more client-side
scripting. The ability to debug client-side script can save
tremendous amounts of time when trying to find bugs in it or when
simply trying to understand the flow of the application.
