Saturday, October 25, 2008

How to Debug the JavaScript code using visual studio 2005?

It is very hectic to debug JavaScript by writing alert code inside the function blocks to test whether it reaches the corresponding line. So visual studio presents a new way to debug JavaScript using a keyword

Debugger inside the function block.

Traditional JavaScript debugging:

Normally developers would add a alert message to test javascript .

function TestDebugging()

{

alert(“I m inside the code”);

}

input type = “button” id =”btn” value =”test” onClick=”javascript:TestDebugging();”

But this type of debugging doesn't say that whether the object is initialized or assigned or not but if we use visual studio to debug JavaScript it will give you what u exactly needed.

Following are the steps to debug JavaScript using Visual studio

Step:1

Write a javascript code using Visualstudio 2005 for example

function TestDebugging()

{

debugger;

alert(“I m inside the code”);

}

we need to include a keyword “debugger;” at the start point of the function block of the JavaScript code.

Step:2

We need t to uncheck the internet options present in the IE or other Browser namely

Disable script debugging (internet explorer)

Disable script debugging (others)

To uncheck the above options go to Internet Explorer --> Tools ---> Internet Options
















Select advanced tab, you will find the above two options

Step3:

Check the settings of internet options as per above picture. Then what for u waiting for just add a keyword debugger; and make settings as per the above picture and enjoy JavaScript debugging.

No comments: