How to fix JavaScript Errors






3.65/5 (11 votes)
Several methods to debug JavaScript
Introduction
I have always seen people asking questions on JavaScript. If we know how to debug JavaScript like any other programming language, we don't need much help on this topic.How to Solve the Problem
First Method
So here is the trick: .NET has given us the facility to debug JavaScript, but before that, we need to do some settings in Internet Explorer.- Tools → Internet Options → Advanced Tab
- Uncheck Disable script debugging (Internet Explorer) & Uncheck Disable script debugging (Others) and restart Internet Explorer
debugger
keyword as shown below:
function Disable(controlId) {
debugger
document.getElementById(controlId.id).disabled = true;
window.open("second.htm");
}
Now open your page in Internet Explorer and try to execute the function, so if the JavaScript is called on a button click, click the button. Now you will see a pop up which would give you a Visual Studio just-in-time debugger. Now select the Visual Studio instance where you want to debug JavaScript in, and click on yes and try to solve your problem.
Second Method
Another way is to replace thedebugger
keyword with any word which would give a JavaScript error. Let us look at it with the same example given above.
function Disable(controleid) {
dsfsdf;
document.getElementById(controleid.id).disabled = true;
window.open("second.htm");
};
Now in this case, instead of showing you the JIT debugger, it would give you the error asking "Do you want to debug this web page?", along with some error details. Click on "yes" and it will show you the JIT debugger.