.NET 2005

  • Thread starter Thread starter Guest
  • Start date Start date
How can I debug javascript code on a page while the page is running?

Use the JavaScript debugger method...

E.g.

<script>

var strMessage="Hello";
debugger;
alert(strMessage);

</script>

Run your app in debug mode (F5, not Ctrl-F5), and execution will stop on the
debugger; line.
 
In IE, tools options advanced, ensure that disable script debugging is
unchecked.

in VS, debug to your page and once loaded, you can either go to debug ->
windows - runing documens or use CTRL-ALT-N to bring up the script
explorer, you then select the page you want to debug and then you can set
breakpoints in the js and when the breakpoint is hit, step through it.

-Adrian

(for some reason the running docs window is missing on my VS, so I use the
CTRL-ALT-N approach)

| How can I debug javascript code on a page while the page is running?
|
| Thanks,
|
| Victor
|
|
 
Hi Victor,

Besides other community member's useful input, you may also checkout
following articles:

#How to: Enable Client-Side Script Debugging
http://msdn2.microsoft.com/en-us/library/k2h50zzs.aspx

I hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,

Mark said:
Use the JavaScript debugger method...

E.g.

<script>

var strMessage="Hello";
debugger;
alert(strMessage);

</script>

Run your app in debug mode (F5, not Ctrl-F5), and execution will stop on the
debugger; line.

I would rather recommend a method which doesn't need to modify the
source code: Simply put a breakpoint in the code...

HTH,
Laurent
 
I would rather recommend a method which doesn't need to modify the source
code: Simply put a breakpoint in the code...

You're right, of course. It's an old (and, no doubt, bad) habit of mine from
back in the day when this was the only reliable way of debugging
JavaScript...

Did you ever try to set a breakpoint in JavaScript in Visual Studio 6...?
:-)
 
Hi,

Mark said:
You're right, of course. It's an old (and, no doubt, bad) habit of mine from
back in the day when this was the only reliable way of debugging
JavaScript...

Did you ever try to set a breakpoint in JavaScript in Visual Studio 6...?
:-)

Never had to do that ;-)

Back in the days, I was using Venkman only for debugging, and before
that the Netscape javascript debugger (or whatever it was called) and
before that.... the old "alert" methods ;-)

Greetings,
Laurent
 
Hi

I always get "This is not a valid location for a breackpoint" when ever I
try to insert a break point on the aspx html code. Any ideas?

thanks,

Victor
 
Hi,

Hi

I always get "This is not a valid location for a breackpoint" when ever I
try to insert a break point on the aspx html code. Any ideas?

thanks,

Victor

In my experience, setting breakpoints in inline JavaScript code doesn't
always work. The best is to place your JavaScript code in external JS
files. This has many other advantages too anyway (files are cached,
modularity, reusability...).

HTH,
Laurent
 
I always get "This is not a valid location for a breackpoint" when ever I
try to insert a break point on the aspx html code. Any ideas?

What happens if you use the JavaScript debugger method...?
 
thanks that took care of the problem.

Victor

Laurent Bugnion said:
Hi,



In my experience, setting breakpoints in inline JavaScript code doesn't
always work. The best is to place your JavaScript code in external JS
files. This has many other advantages too anyway (files are cached,
modularity, reusability...).

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
JavaScript code can be debugged, but not in the same way as ASP.Net, because
it is client-side code. For debugging JavaScript, you set up Internet
Explorer to allow JavaScript debugging, use the Tools|Options menu, and the
Advanced tab. Uncheck the "Disable Script Debugging (Internet Explorer)"
item. Then, when a bug occurs in client-side JavaScript, IE will allow you
to launch a debugger to debug the script (usually Visual Studio). You can
also set a break point in JavaScript by adding the following line of
JavaScript where you want the debugger to break:

debugger;

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.
 
Hi,

Kevin said:
JavaScript code can be debugged, but not in the same way as ASP.Net, because
it is client-side code. For debugging JavaScript, you set up Internet
Explorer to allow JavaScript debugging, use the Tools|Options menu, and the
Advanced tab. Uncheck the "Disable Script Debugging (Internet Explorer)"
item. Then, when a bug occurs in client-side JavaScript, IE will allow you
to launch a debugger to debug the script (usually Visual Studio). You can
also set a break point in JavaScript by adding the following line of
JavaScript where you want the debugger to break:

debugger;

True but incomplete. You can set breakpoints in client-side JavaScript
code using F9 and *without* modifying the code by adding the debugger
statement. That would be the recommended way.

Similarly, you can also attach the VS2005 debugger to a running instance
of IE and debug the client-side code, even if the page is served by a
remote sever.

In that sense, it's very similar to ASP.NET, except that the code runs
in another process.

HTH,
Laurent
 
This is a Visual Studio bug. Instead of using

<script />
use
<script></script>

You should be able to set breakpoints after changing.
 
Back
Top