Click here to Skip to main content
Click here to Skip to main content

Using Visual Studio to Debug JavaScript in IE

By , 24 May 2007
Rate this:
Please Sign up or sign in to vote.

Using break points to debug your javascript

Introduction

Anyone who has done some work with JavaScript knows it can be very frustrating. Often you have to use: Alert("I am here"); type of code to debug it. Visual Studio and IE (Internet Explorer) have the ability to debug JavaScript code, including setting break points in your JavaScript.

Background

When I started working in .NET, I was a VB.NET Windows programmer. When I started to use ASP.NET, the need to use JavaScript started to come up. It was easy for me to make mistakes in my JavaScript since it is a C based language, so there was a real need to have the ability to debug my JavaScript code. I don't think I would have ever ventured into the JavaScript world without being able to debug it in Visual Studio.

Setup

In IE you have to enable script debugging. Go to Tools, then Internet Options. Click on the Advanced Tab. Un-check disable script debugging (Internet Explorer). It is checked by default.

Advanced tab to enable script debugging

NOTE: you will find with script debugging enabled that many Internet sites have lots of JavaScript problems. So I would suggest only turning this on when you want to debug your JavaScript otherwise you will be bothered by IE asking you if you want to debug other peoples bad JavaScript.

Once you have this set, a new option is available in your View menu. If you click on View there is now a script debugger option. If you are using IE 7 you will need to click on Tools, then Menu bar to see the View menu item.

Screenshot - Scriptdebug1.gif

So at this point in Visual Studio, if you set your web project / web site to debug mode and run it, you can debug your JavaScript.

Under View/Script Debugger there are two options. The first is Open.

Screenshot - Scriptdebug3.gif

This will open the HTML/JavaScript in Visual Studio and allow you to set break points in your JavaScript.

Screenshot - Scriptdebug4.gif

The other option is Break at next statement which does just what it says. When the next JavaScript gets run, you will go into Visual Studio and it will break on the first JavaScript line.

Screenshot - Scriptdebug6.gif

Once you are in the Visual Studio debugger, you can use all of the normal tools you have to investigate variables etc. to help with the debugging of the JavaScript code.

Using VS tools to debug

Conclusion

I have found that being able to debug my JavaScript has really helped me to find all the small problems and bugs that are so easy to create when writing JavaScript code.
I hope this article helps you in your JavaScript debugging.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

kubben
Web Developer
United States United States
I started my programmer career over 18 years ago doing COBOL and SAS on a MVS mainframe. It didn't take long for me to move into windows programming. I started my windows programming in Delphi (Pascal) with a Microsoft SQL server back end. I started working with vb.net when the beta 2 came out in 2001. After spending most of my programming life as a windows programmer I started to check out asp.net in 2004. I achieved my MCSD.net in April 2005. I have done a lot of MS SQL database stuff. I have a lot of experience with Window Service and Web services as well. I spent three years as a consultant programing in C#. I really enjoyed it and found the switch between vb.net and C# to be mostly syntax. In my current position I am programming in both vb.net and C#. Lately I have been using VS2012 and writing a Windows 8 app. You can search for the app it is called ConvertIT.
 
On a personal note I am a born again Christian, if anyone has any questions about what it means to have a right relationship with God or if you have questions about who Jesus Christ is, send me an e-mail. ben.kubicek[at]netzero[dot]com You need to replace the [at] with @ and [dot] with . for the email to work. My relationship with God gives purpose and meaning to my life.

Comments and Discussions

 
GeneralIs there a system field that hold the value of a JavaScript delimiter? : or $ Pinmembersmcirish10-Mar-09 4:16 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmemberkubben10-Mar-09 4:25 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmembersmcirish10-Mar-09 4:47 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmemberkubben10-Mar-09 4:50 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmembersmcirish10-Mar-09 6:05 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmemberkubben10-Mar-09 6:11 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmembersmcirish10-Mar-09 6:43 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmemberkubben10-Mar-09 7:50 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmembersmcirish10-Mar-09 7:58 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pinmemberkubben10-Mar-09 8:07 
GeneralThanks it is giong to help all JS user Pinmembersantosh d30-Jan-09 19:21 
GeneralRe: Thanks it is giong to help all JS user Pinmemberkubben31-Jan-09 1:12 
GeneralThank you! Pinmembermohamed antar4-Aug-07 3:28 
GeneralRe: Thank you! Pinmemberkubben4-Aug-07 6:15 
Questionwhat abt web resource file PinmembertheMukesh12330-May-07 19:32 
AnswerRe: what abt web resource file Pinmemberkubben31-May-07 1:49 
GeneralSome Other Debugging Tips [modified] PinmemberNick Taylor30-May-07 3:01 
GeneralRe: Some Other Debugging Tips Pinmemberkubben30-May-07 3:17 
GeneralAnother side note PinmemberBrad Ford29-May-07 7:36 
GeneralRe: Another side note Pinmemberkubben29-May-07 7:41 
Generalthanks! Pinmemberstefano piuri29-May-07 2:47 
GeneralRe: thanks! Pinmemberkubben29-May-07 2:54 
Generalside note Pinmemberdustkicker28-May-07 22:36 
GeneralRe: side note Pinmemberkubben29-May-07 1:37 
GeneralThanks! Pinmembermerlin98124-May-07 11:35 
GeneralRe: Thanks! Pinmemberkubben24-May-07 13:50 
GeneralRe: Thanks! PinmemberOrcrist24-May-07 18:25 
GeneralRe: Thanks! Pinmemberkubben25-May-07 1:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 24 May 2007
Article Copyright 2007 by kubben
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid