Debugging Javascript in IE7

Broken Javascript in IE *really* sucks as one gets really obscure error messages and alert(); becomes your only friend, or so I thought.

I've recently done quite a lot of javascript DOM work for a site including some AJAX stuff and whilst it was a pleasure to develop in Firefox using Firebug, I'm now getting “it doesn't work” errors with IE 7 and I need something more. A bit of Googling comes up with a couple of useful links here and here which looked like good advice, so I followed it thus:

Fire up IE7

Tools -> Internet Options -> Advanced: Disable script debugging (Internet Explorer) is ticked, untick it.

Restart IE.

Right click on the menu bar area and enable the Menu bar (mine was hidden anyway) then go to
View -> Script Debugger -> Open.

If you don't get a pop-up asking you to choose a debugger (I didn't) then you need to install the Microsoft script editor which comes with MS Office (weirdly).

Just to check, Windows-key and F should bring up a search, look for MSE7.exe if you don't have it (I didn't) put your office CD in and run setup. Under office tools -> HTML Tools -> Web scripting -> Web debugging, right click and select “Run from my computer”.

Restart IE.

View -> Script Debugger -> Open should now give you your pop-up, yay!

Now you can open your page in IE and make it break, when it does you shoudl get a “Do you want to debug” message. Yes we do so a press of 'Yes' gives us the same pop-up, selecting the Script editor allows us to do things other than just adding alerts() everywhere. For example we can pause the interpreter, step over each line, add watches and other normal debug things.

In conjunction with the View DOM option in the IE 7 developers toolbar IE almost doesn't suck so much now.

Using the debugger doesn't automatically fix your code, though.

Refererences:

http://erik.eae.net/archives/2005/07/04/21.49.50/
http://www.jonathanboutelle.com/mt/archives/2006/01/howto_debug_jav.html

p.s. I only tried the other debugger option once, it didn't look all that so I stopped using it.