self.onerror help?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug O'Leary

    self.onerror help?

    Hey;

    I'm completely new to javascript and am slowly working my way through
    the O'Reilly's Javascript, the Definitive Guide. One of the examples
    is supposed to pop up an alert box if there's a javascript error. I
    typed in the code pretty much as documented but it didn't work. In
    an attempt to troubleshoot, I simplified the thing but it's still
    not working. The html and javascript code is posted below. Can
    someone tell me what I screwed up?

    I've hit the page with Opera 7.54, IE 6 and Netscape 7.0. Same results
    in all three. I get the message between the <h1> tags but not the
    alert window. All popup blockers have been turned off as well.

    Thanks for any help.

    Doug O'Leary

    <html>
    <body>
    <script>
    var error_count = 0;
    var email = "dkoleary";

    // Create the error handler function
    function report_error(ms g, url, line)
    { alert("You attempted bad!");
    return true;
    }
    self.onerror = report_error;
    </script>

    <h1>Display something!</h1>
    <hr>

    <script>
    alert(no_such_v ariable);
    </script>
    </body></html>
  • Lee

    #2
    Re: self.onerror help?

    Doug O'Leary said:[color=blue]
    >
    >Hey;
    >
    >I'm completely new to javascript and am slowly working my way through
    >the O'Reilly's Javascript, the Definitive Guide. One of the examples
    >is supposed to pop up an alert box if there's a javascript error. I
    >typed in the code pretty much as documented but it didn't work. In
    >an attempt to troubleshoot, I simplified the thing but it's still
    >not working. The html and javascript code is posted below. Can
    >someone tell me what I screwed up?[/color]
    [color=blue]
    > self.onerror = report_error;[/color]

    Try:

    window.onerror = report_error;

    works in IE 6 and Firefox 1.0.1

    Comment

    • Doug O'Leary

      #3
      Re: self.onerror help?

      On 2005-03-03, Lee <REM0VElbspamtr ap@cox.net> wrote:[color=blue]
      >
      > Try:
      >
      > window.onerror = report_error;
      >
      > works in IE 6 and Firefox 1.0.1[/color]

      Thanks. That got it working in IE & netscape, but not opera. According
      to the book, self is supposed to be a synonym to the window property.
      Guess it's not implemented in whatever version of javascript is running
      in the various browsers that I have.

      Thanks for the tip; I appreciate it.

      Doug O'Leary

      Comment

      • Christopher Benson-Manica

        #4
        Re: self.onerror help?

        Doug O'Leary <dkoleary@olear ycomputers.com> spoke thus:
        [color=blue]
        > Thanks. That got it working in IE & netscape, but not opera. According
        > to the book, self is supposed to be a synonym to the window property.
        > Guess it's not implemented in whatever version of javascript is running
        > in the various browsers that I have.[/color]
        [color=blue]
        > Thanks for the tip; I appreciate it.[/color]

        If it makes you feel any better, I have the same book and experienced
        the same frustration with making this particular example work,
        although I still believe it's a fine book overall.

        --
        Christopher Benson-Manica | I *should* know what I'm talking about - if I
        ataru(at)cybers pace.org | don't, I need to know. Flames welcome.

        Comment

        Working...