Debugging JavaScript In Internet Explorer Is Terrible
6/10/2008
Development
(0)
One of the most frustrating aspects of creating web applications these days has become JavaScript debugging. Gone are the days of plan old form fields to fill out, users these days need client-side validation, modal-popup windows, calendar objects, and animations that "look cool".
While the AJAX control toolkit will give you a lot of this functionality, you need to get your hands dirty with JavaScript to do anything above and beyond what they offer. On one of my current projects, we've got JavaScript validation, JavaScript functions to open modal-popups, and I believe there is a JavaScript function that calculates the user's favorite color based on which items they hover the mouse over longest and which they avoid (okay, not really that last one).
With all of this reliance on JavaScript, it baffles me that Internet Explorer can be so terrible at debugging it (I run IE 7). First of all, it's hard to use IE to find even where the JavaScript errors are. When you view the details of an error, it gives you a line and character number. More often than not, I find both of these to be zero (completely unhelpful). Sometimes you get a legit line number, and if you're really lucky it matches either a line in your code or a line in the source of the page (though don't count on it).
The error messages IE gives out for JavaScript are equally vague. You might see something like "Expected ;", which tends to mean there is a syntax error somewhere in your code, but the way JavaScript gets parsed, it is in all likelihood far before the line IE says the error occurred on. That seems to be a pretty common occurrence with JavaScript errors.
What really got me writing this rant is I've been struggling with a JavaScript function for passing data between a parent and child window. For some reason, when I call "window.close();" in the child window, it closes that child window and opens a new one. IE didn't see any errors, just exhibited this odd behavior. After smashing my head on the desk several dozen times and being treated for the subsequent concussion, I opened up FireFox which promptly told me exactly where the error was occurring (in a completely different validation function strangely enough). It's crazy that a newcomer like FireFox can so outshine the long established Internet Explorer in this area.
Which brings me to another point... if you want to debug JavaScript (or issues with the DOM for that matter), use FireFox and the Firebug plug-in. Not only is the error reporting better, but you can actually step through JavaScript functions and see what's going on. I think I read that Visual Studio 2008 has some built in JavaScript debugging, which would be great if it's true (assuming it's better than what IE offers), but it will still be a few months before I can make the leap to 2008. Until then, I'm just going to complain.
This article has been view 964 times.
|