Dec/083
Debug JavaScript in Internet Explorer
If you have ever had the horror of finishing up some complex JavaScript in Firefox, and when you try it in IE you just get a bunch of usless and cryptic errors that all point to the wrong line of code, this article is for you. You can actually get a full debugger for Internet Exploerer for free that is about as cabable as debugging Javascript as Firebug is in Firefox. There is no plugin or addon for IE that will give you a firebug like experience, but with a little extra downloading and work you can get a setup that will allow you to set break points and inspect objects in JavaScript applications in IE. First thing you will need to download the free Visual Web Developer Express IDE from Microsoft Visual Web Developer is like Firebug for Internet Explorer, only it is not an addon and you have to do a bunch of setup befure it will be useful. It is free but it will cost you more than 200 megs of hard drive space and about an hour of downloading and installing.
Once you have Visual Web Developer Express installed launch the IDE and create a new blank web site:
File >> New Web Site
Select “Empty Web Site” and give the project a name and click OK.
If your default web browser is something other than IE you will need to setup Visual Web Developer do debug in Internet Explorer by default.
On the right side of the IDE you will find the Solution Exploerer, right click on your solution and select “Browse With”. In the browse with window select Internet Explorer and click the Set as Default button. This will not change your system default browser just the browser that will be used by this solution by default. Once you have IE set as default for the solution you can click cancel.
Now you need to make sure IE is ready to be debugged. Open Internet Explorer, click on Tools >> Options, select the Advanced tab and remove the check from “Disable Script Debugging (Internet Explorer)” and click OK.
Now you are ready. Switch back to Visual Web Developer and press F5 to start debugging. If this is the first time you have launched this solution Visual Web Developer may display a dialog stating that a web.config could not be found. If you recieve this dialog choose “Add a new web.config…” and click ok. This should launch Internet Explorer with an error page, just type in the URL of the page you want to debug in the address bar. Once the page loads if you switch back to Visual Web Developer Express you will see all of the files loaded by the page in the Solution Explorer on the right. Double click the file with the JavaScript you wish to debug, which will open the file in the IDE. You can now set break points where you want them. Once you have your break points set switch back to IE and take the action that will execute the code you are debugging and Visual Web developer will stop on your break points letting you inspect the objects and variables at that point.
To make the process easier you can right click on the solution in the solution explorer and select “Add New Item”. From the presented installed templates choose “HTML Page”, and name it index.htm. In the head of the generated HTML add a meta refresh to go to the page you wish to debug. e.g. <meta http-equiv=”refresh” content=”0;url=http://www.yourdomain.com/pagetodebug.html” />. After adding that when you debug it will automatically redirect to the page you are working on.