Click here to Skip to main content
11,704,315 members (59,474 online)
Click here to Skip to main content

Using Visual Studio to Debug JavaScript in IE

, 24 May 2007 CPOL 131.3K 55
Rate this:
Please Sign up or sign in to vote.
Using Visual Studio to debug JavaScript in IE can really speed up your JavaScript development and save you some headaches

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)

Share

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.

You may also be interested in...

Comments and Discussions

 
QuestionThanks.. it works for me Pin
vipul200821-Jul-15 1:29
membervipul200821-Jul-15 1:29 
QuestionIt work with any browser ?? Pin
Eng Kerollos Adel18-May-15 2:18
groupEng Kerollos Adel18-May-15 2:18 
GeneralMy vote of 3 Pin
AparnaSpan11-Jul-14 5:06
memberAparnaSpan11-Jul-14 5:06 
GeneralRe: My vote of 3 Pin
kubben11-Jul-14 5:08
memberkubben11-Jul-14 5:08 
GeneralIs there a system field that hold the value of a JavaScript delimiter? : or $ Pin
smcirish10-Mar-09 4:16
membersmcirish10-Mar-09 4:16 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
kubben10-Mar-09 4:25
memberkubben10-Mar-09 4:25 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
smcirish10-Mar-09 4:47
membersmcirish10-Mar-09 4:47 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
kubben10-Mar-09 4:50
memberkubben10-Mar-09 4:50 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
smcirish10-Mar-09 6:05
membersmcirish10-Mar-09 6:05 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
kubben10-Mar-09 6:11
memberkubben10-Mar-09 6:11 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
smcirish10-Mar-09 6:43
membersmcirish10-Mar-09 6:43 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
kubben10-Mar-09 7:50
memberkubben10-Mar-09 7:50 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
smcirish10-Mar-09 7:58
membersmcirish10-Mar-09 7:58 
GeneralRe: Is there a system field that hold the value of a JavaScript delimiter? : or $ Pin
kubben10-Mar-09 8:07
memberkubben10-Mar-09 8:07 
GeneralThanks it is giong to help all JS user Pin
santosh d30-Jan-09 19:21
membersantosh d30-Jan-09 19:21 
GeneralRe: Thanks it is giong to help all JS user Pin
kubben31-Jan-09 1:12
memberkubben31-Jan-09 1:12 
GeneralThank you! Pin
mohamed antar4-Aug-07 3:28
membermohamed antar4-Aug-07 3:28 
GeneralRe: Thank you! Pin
kubben4-Aug-07 6:15
memberkubben4-Aug-07 6:15 
Questionwhat abt web resource file Pin
theMukesh12330-May-07 19:32
membertheMukesh12330-May-07 19:32 
AnswerRe: what abt web resource file Pin
kubben31-May-07 1:49
memberkubben31-May-07 1:49 
GeneralSome Other Debugging Tips [modified] Pin
Nick Taylor30-May-07 3:01
memberNick Taylor30-May-07 3:01 
GeneralRe: Some Other Debugging Tips Pin
kubben30-May-07 3:17
memberkubben30-May-07 3:17 
GeneralAnother side note Pin
Brad Ford29-May-07 7:36
memberBrad Ford29-May-07 7:36 
GeneralRe: Another side note Pin
kubben29-May-07 7:41
memberkubben29-May-07 7:41 
Generalthanks! Pin
stefano piuri29-May-07 2:47
memberstefano piuri29-May-07 2:47 
GeneralRe: thanks! Pin
kubben29-May-07 2:54
memberkubben29-May-07 2:54 
Generalside note Pin
dustkicker28-May-07 22:36
memberdustkicker28-May-07 22:36 
GeneralRe: side note Pin
kubben29-May-07 1:37
memberkubben29-May-07 1:37 
GeneralThanks! Pin
merlin98124-May-07 11:35
membermerlin98124-May-07 11:35 
GeneralRe: Thanks! Pin
kubben24-May-07 13:50
memberkubben24-May-07 13:50 
GeneralRe: Thanks! Pin
Orcrist24-May-07 18:25
memberOrcrist24-May-07 18:25 
GeneralRe: Thanks! Pin
kubben25-May-07 1:37
memberkubben25-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 | Terms of Use | Mobile
Web02 | 2.8.150819.1 | Last Updated 24 May 2007
Article Copyright 2007 by kubben
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid