Debugging JavaScript in Netscape
JavaScript and Netscape. Now there are two words that, when heard in the same sentence, put the fear of god in me. I know that Netscape invented JavaScript but that doesn't distract from the fact that getting anything to work in it is a pain. The worst part has to be when it comes to debugging. The version I have installed on my PC here at work is 4.5. When I get an error it very kindly tells me so in the Status Bar.
Why do we have to type "javascript:" in to the "Location"? Why can't it just tell us? Rather annoying when we are doing lots of debugging to have to type this in every time. Also, if you are as stupid as me, and you type "javascript" instead of "javascript:" then you are left totally clueless.
What we really want is something more like Internet Explorer where the reported error is a little easier to find. We can even take it one step further and actually debug the code, as discussed in this article. This is possible in Netscape using the Netscape JavaScript Debugger 1.1 . However, as with everything Netscape it is bugful. Getting it installed is one thing. Starting it and using it is a whole different ball-game.
Let's see if we can't make it a little simpler. Using the onerror event of the window object we can call a function that alerts the user (or developer if it's only being used in debug mode) what the error was and how it ocurred. First thing to do is write the function to handle the errors:
function errorHandler( e, f, l ){Returning true at the end of the function tells Netscape not to bother doing its own messages, whereas false lets it do its own stuff. All we need do now is assign this function to the window's onerror event:
alert("An error has ocurred in the JavaScript on this
page.\nFile: " + f + "\nLine: " + l + "\nError:" + e);
return true;
}
if (navigator.appName == "Netscape")Notice that we only assign this to the onerror event for Netscape, after all, Internet Explorer does a pretty good job already. So, what does this do? Well instead of reporting the error to the status bar we get a prompt like the one below:
window.onerror = errorHandler;
This popped up when I clicked a button that ran code that with a call to a variable called "trigger". Obviously here I mistyped it.
In summary this is still by no means a perfect solution, but is definitely a whole lot nearer that what we had been given. The adventurous amongst may well go and download the JavaScript debugger for Netscape. Good luck.
Those of us who have started using Version 6.0 may be relieved to have found the JavaScript error console. However this still isn't exactly the perfect solution. It still begs the question: Where EXACTLY is the error!!??!?!
Maybe they will get it right in version 7.0. Or maybe 8.0, or 9.0 or......
Netscape 7.x
The horrible truth is that Netscape invented JavaScript and that there appears to be little or no conformance to a "standard". The nice people at Microsoft have a nasty habit of breaking standards or simply changeing them and saying "we are Microsoft so this is the new standard" along with extensions and modifications to either Java or JavaScript. In the end I need to write web applications that will operate the same in both Windows and Linux/Unix environments. I depend on the W3C HTML Validator to confirm that my pages are correct HTML 4.01 and I use Domino web agents to output most of my critical pages as that allows fine control over the page. Netscape seems to be a better tool to use for those of us that are not addicted to Microsoft virusware. We at least have choices for our browser and may use Amaya, Konqueror, Mozilla or even text based links/lynx. The W3C Validator solves a lot of problems but Javascript, as your article suggests, is a pain in my side for cross platform/browser functionality.
Dennis
Reply
Debugging in NetScape
I have been using Venkman as the debugger for Netscape 7.2 and it has simplified my life. It has breakpoints, single steps through JavaScript, watches and displays current values of variables. It sure beats scattering alerts throughout my code.
Reply