One thing I have noticed is that there are numerous ways to debug javascript with visual studio. I thought I would share some of them that I have found over the years.
- In internet explorer you can go to view->script debugger->Break
at next statement. This will cause the debugger to run when the next
javascript statement runs in the browser. This is not a feature that is
enabled by default. To enable it you will need to go to the advanced
tab in internet options and uncheck the "Disable Script Debugging"
option and restart IE. This is the method I use most often.
- Force javascript to call the debugger. You can do this like so in your javascript:
function DoTask()
{
debugger;
return 3+7;
}
when the browser encounters the debugger statement it will lanch vs and you can step through your code. - In visual stuido attach the debugger to the Internet Explorer property
and select script as what you want to debug. On the right hand side
where solution explorer is you should see a tab called running
documents. Select the document to debug and set any breakpoints you
wish to step through.
- Use Firefoxes javascript console to spot errors. It is the icon in the top right hand corner and will show a list of javascript errors on the page which is quite handy at a glance.
- If you are a firefox user you can also call Ghost Busters. By that I mean install the Venkman Javascript debugger for firefox that allows you to debug firefox (get it here: http://www.mozilla.org/projects/venkman/). I have only used it once and perfered using the IE methods myself. But if you don't have a script debugger installed on your machine this is a good solution.
Print | posted on Thursday, August 10, 2006 2:46 PM