Click here to Skip to main content
Click here to Skip to main content
Go to top

How to fix JavaScript Errors

, 8 May 2011
Rate this:
Please Sign up or sign in to vote.
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
Now in a Visual Studio Project, on the aspx page in the script blog, type the 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 the debugger 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.
 

Third Method

If this process is lengthy, then you can use the Developers Tool given in Internet Explorer. You will find it in
Tools → Developer Tools, or simply press F12.
 
Now go to the script tab. Just like you place debug pointer in Visual Studio, place a debug point on the left hand side corner on the place where you want to debug, and click on start debugging to start debugging your code.
 
For Firefox, install the Firebug add-on. You will see Firebug in tools, and also on the right corner of the browser.
 
You get developer tools for almost all browsers so now you can check and debug your JavaScript.

License

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

Share

About the Author

Steven.Pinto2000

United States United States
No Biography provided
Group type: Social Group (No members)



Comments and Discussions

 
GeneralReason for my vote of 4 useful about debugger keyword Pinmemberseaplanner11-Oct-11 5:24 
Generalcool :) PinmemberShahriar Iqbal Chowdhury8-May-11 10:30 
GeneralNice. PinmemberShahista.Shaikh7-May-11 3:29 
GeneralRe: then you can rate me PinmemberSteven.Pinto9-May-11 1:09 
GeneralWill be handy! :thumbsup: PinmvpS Mewara6-May-11 19:50 
GeneralRe: Thank you PinmemberSteven.Pinto6-May-11 20:04 

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
Web03 | 2.8.140916.1 | Last Updated 8 May 2011
Article Copyright 2011 by Steven.Pinto2000
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid