Does Event handlers work in netscape.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chandramohan.mani@gmail.com

    #1

    Does Event handlers work in netscape.

    Does Event handlers work in netscape. If yes means can anyone please
    help me.

    <HTML><SCRIPT LANGUAGE="JScri pt">
    function mouseclick() {
    alert("I was clicked on " + window.event.sr cElement.tagNam e);
    }
    </SCRIPT>
    <BODY onclick="mousec lick()">
    <H1>Welcome!</H1>
    <P>This is a very <B>short</B> document.

    </BODY>
    </HTML>

    The above script works fine in IE

    But not in Netscape 7.2 :((

  • paul.andrei@gmail.com

    #2
    Re: Does Event handlers work in netscape.

    testing

    Comment

    • Dietmar Meier

      #3
      Re: Does Event handlers work in netscape.

      chandramohan.ma ni@gmail.com wrote:
      [color=blue]
      > The above script works fine in IE
      > But not in Netscape 7.2 :(([/color]

      Try this modification:

      function mouseclick(e) {
      var what = e.target || e.srcElement;
      if (what) alert("I was clicked on " + what.tagName);
      }
      [...]
      <body onclick="mousec lick(event)">

      ciao, dhgm

      Comment

      • RobG

        #4
        Re: Does Event handlers work in netscape.

        Dietmar Meier wrote:[color=blue]
        > chandramohan.ma ni@gmail.com wrote:
        >[color=green]
        >> The above script works fine in IE
        >> But not in Netscape 7.2 :(([/color]
        >
        >
        > Try this modification:
        >
        > function mouseclick(e) {[/color]

        if (!e && window.event) var e = window.event;

        I'm not near an IE box right now, but I think to keep IE happy you'll
        need to add the above line before:
        [color=blue]
        > var what = e.target || e.srcElement;[/color]
        [...]

        I'm playing in Safari at the moment, it seems to support a bit of both
        Firefox/Netscape and IE (but often neither...) so I can't test it in
        IE.

        You may only need the extra line if you don't pass 'event' with the
        onclick call.


        --
        Rob

        Comment

        • Martin Honnen

          #5
          Re: Does Event handlers work in netscape.



          chandramohan.ma ni@gmail.com wrote:
          [color=blue]
          > Does Event handlers work in netscape.[/color]

          Yes, event handlers work in Netscape, depending on the Netscape version
          not all event handlers specified in HTML 4 might work but with Netscape
          6/7 there is certainly support for HTML 4 and for DOM Level 2 Events.
          [color=blue]
          > <HTML><SCRIPT LANGUAGE="JScri pt">
          > function mouseclick() {
          > alert("I was clicked on " + window.event.sr cElement.tagNam e);[/color]

          Have you checked the JavaScript console? It probably shows you that
          window.event
          is undefined or not an object with Netscape 6/7
          [color=blue]
          > <BODY onclick="mousec lick()">[/color]

          so the problem is not that the onclick handler is not being fired but
          that your script being called then throws an error.
          You can pass the event object to a function e.g.
          <body onclick="mousec lick(event);">
          and then you need to process that argument in the function e.g.
          function mouseclick (evt) {
          and then you need to be aware that properties of the event object differ
          in IE and in Netscape, IE docs are here:
          <http://msdn.microsoft. com/library/default.asp?url =/workshop/author/dhtml/reference/objects/obj_event.asp>
          Netscape 6/7 implements the W3C DOM as given here:
          <http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-Event>
          <http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-UIEvent>
          <http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-MouseEvent>

          You already got an answer showing to access target with Netscape (or
          other browser supporting that) and srcElement with IE (or other browsers
          supporting that).


          --

          Martin Honnen
          http://JavaScript.FAQTs.com/

          Comment

          • Martin Honnen

            #6
            Re: Does Event handlers work in netscape.



            RobG wrote:
            [color=blue]
            > Dietmar Meier wrote:
            >[/color]
            [color=blue][color=green]
            >> Try this modification:
            >>
            >> function mouseclick(e) {[/color]
            >
            >
            > if (!e && window.event) var e = window.event;
            >
            > I'm not near an IE box right now, but I think to keep IE happy you'll
            > need to add the above line before:
            >[color=green]
            >> var what = e.target || e.srcElement;[/color][/color]
            [color=blue]
            > You may only need the extra line if you don't pass 'event' with the
            > onclick call.[/color]

            And Dietmar had
            <body onclick="mousec lick(event)">
            in his answer so your line is not needed with his solution.

            --

            Martin Honnen
            http://JavaScript.FAQTs.com/

            Comment

            • Richard Cornford

              #7
              Re: Does Event handlers work in netscape.

              Martin Honnen wrote:[color=blue]
              > chandramohan.ma ni@gmail.com wrote:[/color]
              <snip>[color=blue][color=green]
              >> <HTML><SCRIPT LANGUAGE="JScri pt">[/color][/color]
              ^^^^^^^
              <snip>[color=blue]
              > ... but
              > that your script being called then throws an error.[/color]
              <snip>

              The script certainly would error if executed in Netscape/Mozilla, but
              would they execute script specified as language="JSCRI PT" in the first
              palace?

              Richard.


              Comment

              • chandramohan.mani@gmail.com

                #8
                Re: Does Event handlers work in netscape.

                Thanks for your code. But its not working in Netscape, same problem

                Comment

                • Dietmar Meier

                  #9
                  Re: Does Event handlers work in netscape.

                  chandramohan.ma ni@gmail.com wrote:
                  [color=blue]
                  > Thanks for your code. But its not working in Netscape, same problem[/color]

                  In addition to my code, see Richard's answer. Instead of

                  <SCRIPT LANGUAGE="JScri pt">

                  (which is MSIE-proprietary) you should use

                  <script type="text/javascript">

                  to have your code executed in both Netscape7 and MSIE (and
                  other browsers). A complete example document would be:

                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                  "http://www.w3.org/TR/html4/strict.dtd">
                  <html>
                  <head>
                  <meta http-equiv="Content-Script-Type"
                  content="text/javascript">
                  <meta http-equiv="content-type"
                  content="text/html; charset=ISO-8859-1">
                  <title></title>
                  <script type="text/javascript">
                  function mouseclick(e) {
                  var what = e.target || e.srcElement;
                  if (what) alert("I was clicked on " + what.tagName);
                  }
                  </script>
                  </head>
                  <body onclick="mousec lick(event)">
                  <H1>Welcome!</H1>
                  <P>This is a very <B>short</B> document.
                  </body>
                  </html>

                  ciao, dhgm

                  Comment

                  • Martin Honnen

                    #10
                    Re: Does Event handlers work in netscape.



                    Richard Cornford wrote:

                    [color=blue][color=green]
                    >>chandramohan. mani@gmail.com wrote:[/color]
                    >
                    >[color=green][color=darkred]
                    >>><HTML><SCRIP T LANGUAGE="JScri pt">[/color][/color]
                    >
                    > ^^^^^^^
                    >
                    > The script certainly would error if executed in Netscape/Mozilla, but
                    > would they execute script specified as language="JSCRI PT" in the first
                    > palace?[/color]

                    Good catch, Mozilla indeed ignores such a script block.


                    --

                    Martin Honnen
                    http://JavaScript.FAQTs.com/

                    Comment

                    Working...