debugging javascript

Ian Petersen ispeters-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Sun Aug 31 23:48:04 UTC 2008


On Sun, Aug 31, 2008 at 4:26 PM, Paul King <sciguy-Ja3L+HSX0kI at public.gmane.org> wrote:
> The "line numbers" problem has not been really addressed, but I have
> found other ways of rooting out errors. There now appear to be no errors
> reported by the debugger, but there is still one runtime error left: the
> menu simply does not show up. But if I point my browser to "items1.txt",
> the text file displays in the browser. Greasemonkey shows that the file
> is in fact read. However, the list inside the file is not parsed into
> menu items.
>
> I don't know if the problem is that
> XMLHttpRequestObject.OnReadyStateChange is assigned a function but is
> never called. This is the place where the menu is supposed to display.
> But my understanding is that it is not supposed to be called. It is
> supposed to be triggered by an event.
>
> Another culprit is that the list is never parsed for some reason. So, at
> least now I have a couple of leads.

I saved a copy of your page to my disk and browsed to the local copy,
thinking I could play around with it from there.  It failed when you
tried to send null with the XMLHttpRequest.  I think you might want to
send the empty string, instead.

For some reason, though, none of your functions seem to get called
when I browse to the version hosted on your server.  One thing you
might want to try is change

<script language="JavaScript">

to the more modern

<script type="text/javascript">

It could be that Firefox isn't even parsing the script, although that
seems a little weird.

Also, I think you may need to change the following code:

function MouseEvent(e) {
   if (e) {
      this.e=e;
   } else {
      this.e=window.event;
   }

   if (e.pageX) {
      this.x=e.pageX;
   } else {
      this.x=e.clientX;
   }

   if (e.pageY) {
      this.y=e.pageY;
   } else {
      this.y=e.clientY;
   }

   if (e.target) {
      this.target=e.target;
   } else {
      this.target=e.srcElement;
   }
}

First, MouseEvent is probably a bad name for the function because the
DOM spec defines something by the same name and you might be running
into name conflicts.  Second, every bare reference to the variable 'e'
after the first if should probably be referring to 'this.e'.  If the
first if block falls through to the else case, then the variable named
e is probably undefined, in which case every reference thereafter is
going to be an error.

I noticed you're generating debug output with document.write().  You
probably don't want to do that.  If you ever manage to execute a
document.write(), the argument will replace the contents of the
current document, rather than appending to it, so you'll lose
everything.  It would be better to have a <div> with an id like
"debug" that you append to using the DOM.  (ie.
document.getElementById("debug").appendChild(document.createTextNode("debug
comment here"));)

Finally, you may want to start out making your code work in either
Firefox or IE and then add cross-browser compatibility code later.
Some of your confusion may come from your attempts to make the code
work in standards-compliant browsers and IE simultaneously.

Ian
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list