.onmouseover=... syntax question re NN events

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Csaba2000

    #1

    .onmouseover=... syntax question re NN events

    How do I achieve the following in javascript, the
    emphasis being on the NN (6.1) 'event' parameter that
    needs to be declared?

    This is the current method - works just fine:
    <TABLE border id='myTable' onmouseover="ta bleMoused(event )">


    But, because I may or may not want myTable subject to being "Moused",
    I want to have something like:
    <TABLE border id='myTable'>
    <SCRIPT type="text/javascript">
    function prepareForMousi ng() {
    var myTable = document.getEle mentById('myTab le');
    myTable.onmouse over = tableMoused;
    }
    </SCRIPT>


    where
    function tableMoused(evt ) {
    var e = window.event || evt;
    ....
    }


    Now, all this is fine for IE (5.5), but can anyone explain how this is
    supposed to be made proper for Netscape (and Opera)?
    The point being, how can NN know that it should pass the
    event object along as that first param?


    Thanks,
    Csaba Gabor from New York


  • Greg

    #2
    Re: .onmouseover=.. . syntax question re NN events

    had you considered using CSS to control your mouseovers? Then any css
    standard supporting browser should render it correctly.

    Greg.

    Csaba2000 wrote:[color=blue]
    > How do I achieve the following in javascript, the
    > emphasis being on the NN (6.1) 'event' parameter that
    > needs to be declared?
    >
    > This is the current method - works just fine:
    > <TABLE border id='myTable' onmouseover="ta bleMoused(event )">
    >
    >
    > But, because I may or may not want myTable subject to being "Moused",
    > I want to have something like:
    > <TABLE border id='myTable'>
    > <SCRIPT type="text/javascript">
    > function prepareForMousi ng() {
    > var myTable = document.getEle mentById('myTab le');
    > myTable.onmouse over = tableMoused;
    > }
    > </SCRIPT>
    >
    >
    > where
    > function tableMoused(evt ) {
    > var e = window.event || evt;
    > ...
    > }
    >
    >
    > Now, all this is fine for IE (5.5), but can anyone explain how this is
    > supposed to be made proper for Netscape (and Opera)?
    > The point being, how can NN know that it should pass the
    > event object along as that first param?
    >
    >
    > Thanks,
    > Csaba Gabor from New York
    >
    >[/color]

    Comment

    • Csaba2000

      #3
      Re: .onmouseover=.. . syntax question re NN events


      "Greg" <junkmail@green treesoftwaresys tems.com> wrote in message news:AFP8b.3245 $Cu3.2455@edtnp s84...[color=blue]
      > had you considered using CSS to control your mouseovers? Then any css
      > standard supporting browser should render it correctly.[/color]

      Huh, what? Perhaps you could clarify your comments.

      I don't want to control mouseover events. I just want
      to receive proper notification of them.

      Although I've had rendering issues in the past (which I
      would happily discuss further), this is not a post about
      rendering. (But if it were, I would add that so far I have
      not seen much evidence that browser support of CSS
      cursors is hale).

      Csaba Gabor
      [color=blue]
      >
      > Greg.[/color]



      Comment

      • Greg

        #4
        Re: .onmouseover=.. . syntax question re NN events

        I'm sorry, I misread your post.

        I'm not sure I'm knowledgeable enough with javascript to make
        intelligent suggestions regarding capturing mouseover events.

        I thought you were trying to affect how parts of your table displayed
        when it was moused over, which I believe you could accomplish with

        (in the css file you could have entries like)
        ..myclass {background: white}
        ..myclass:hover {background: blue}

        (in the html you could have a t
        <table name=myname class=myclass>

        Sorry if I missed the boat.

        Greg.

        Csaba2000 wrote:[color=blue]
        > "Greg" <junkmail@green treesoftwaresys tems.com> wrote in message news:AFP8b.3245 $Cu3.2455@edtnp s84...
        >[color=green]
        >>had you considered using CSS to control your mouseovers? Then any css
        >>standard supporting browser should render it correctly.[/color]
        >
        >
        > Huh, what? Perhaps you could clarify your comments.
        >
        > I don't want to control mouseover events. I just want
        > to receive proper notification of them.
        >
        > Although I've had rendering issues in the past (which I
        > would happily discuss further), this is not a post about
        > rendering. (But if it were, I would add that so far I have
        > not seen much evidence that browser support of CSS
        > cursors is hale).
        >
        > Csaba Gabor
        >
        >[color=green]
        >>Greg.[/color]
        >
        >
        >
        >[/color]

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: .onmouseover=.. . syntax question re NN events

          "Csaba2000" <news@CsabaGabo r.com> writes:
          [color=blue]
          > I want to have something like:[/color]
          ....[color=blue]
          > var myTable = document.getEle mentById('myTab le');
          > myTable.onmouse over = tableMoused;[/color]
          [color=blue]
          > where
          > function tableMoused(evt ) {
          > var e = window.event || evt;[/color]

          I always write this as:

          evt = evt || window.event; // IE sucks

          (yes, always with the comment :)
          [color=blue]
          > Now, all this is fine for IE (5.5), but can anyone explain how this is
          > supposed to be made proper for Netscape (and Opera)?[/color]

          Have you tested it? I would guess that it works.
          [color=blue]
          > The point being, how can NN know that it should pass the event
          > object along as that first param?[/color]

          There is nothing to know, it always does that.
          Except for IE, browsers call the on<event> handlers with the event
          object as the first (and only) argument.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Csaba2000

            #6
            Re: .onmouseover=.. . syntax question re NN events

            "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message news:u17f7kle.f sf@hotpop.com.. .[color=blue]
            > "Csaba2000" <news@CsabaGabo r.com> writes:[/color]
            ....[color=blue][color=green]
            > > I want to have something like:[/color]
            > ...[color=green]
            > > var myTable = document.getEle mentById('myTab le');
            > > myTable.onmouse over = tableMoused;[/color]
            >[color=green]
            > > The point being, how can NN know that it should pass the event
            > > object along as that first param?[/color]
            >
            > There is nothing to know, it always does that.
            > Except for IE, browsers call the on<event> handlers with the event
            > object as the first (and only) argument.
            >[/color]

            Hi Lasse, thanks for your response. OK, I've got it working now.
            But about your last comment, it wasn't clear to me.

            For example, in the following element declaration, would we not
            call myResponse the event handler, which takes three arguments?
            <BUTTON onClick="myResp onse('frob', event, this)">Click me</button>


            Here is how I have gotten the same fragment to work with dynamic
            event handler assignment:

            <BUTTON>Click me</BUTTON>
            <SCRIPT type="text/javascript">
            //onClick="myResp onse('frob', event, this)"
            myButton = document.getEle mentsByTagName( 'BUTTON')[0]
            myButton.onclic k=function (event) {myResponse('fr ob', event, this)}
            function myResponse (foo, evt, src) {
            alert ("dummy arg: " + foo + "\r\npageX: " +
            evt.pageX + "\r\ntype: " +
            src.type + "\r\nargLen : " +
            arguments.lengt h + "\r\nthis: " +
            (!this?"undefin ed":this.nodeNa me));
            }
            </SCRIPT>

            [Terminology question] What, exactly, is the event handler here?
            Is it myResponse or is it the intermediate step specified in the
            onclick line? In the latter, your comment about a single event
            argument is born out. Interestingly >this< is known about in the
            onclick line (though it's not an argument), but it is not known
            about in myResponse.

            Regards,
            Csaba
            [color=blue]
            > /L
            > --
            > Lasse Reichstein Nielsen - lrn@hotpop.com
            > Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
            > 'Faith without judgement merely degrades the spirit divine.'[/color]


            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: .onmouseover=.. . syntax question re NN events

              "Csaba2000" <news@CsabaGabo r.com> writes:
              [color=blue]
              > But about your last comment, it wasn't clear to me.
              >
              > For example, in the following element declaration, would we not
              > call myResponse the event handler, which takes three arguments?
              > <BUTTON onClick="myResp onse('frob', event, this)">Click me</button>[/color]

              Yes it would.

              There is a significant difference between, e.g., the HTML attribute
              "onclick" and the Javascript element property "onclick".

              You can assign a function directly to the element:
              document.getEle mentById("foo") .onclick = function(event) {...};

              This is a completely normal Javascript function, and it will be called
              as a method of the element with id="foo".

              What you write is an HTML attribute. The attribute value is converted
              to a function and assigned to the element's property. The body
              of this function is the code you wrote, but it is executed in a
              scope where the properties of the document, form and form-element
              elements are visible.

              If you write
              <button id="foo" onclick=" ... some Javascript ..."> ...</button>
              then the onclick property of the corresponding element is creatated
              as (something like, but not exactly):

              var elem = document.getEle mentById('foo') ;
              with (document) {
              with (elem.form) { // if any
              with (elem) {
              elem.onclick = Function("event ","... some Javascript ...");
              }
              }
              }

              Except in IE, the "event" is not an argument of the function, but
              a global variable instead. This becomes visible if you add, e.g.,
              a property called "event" to the document object.

              So, the text in an HTML onclick attribute becomes the body of the
              actual event handler function. The function called from it,
              "myResponse ", is not the event handler.
              [color=blue]
              > myButton.onclic k=function (event) {myResponse('fr ob', event, this)}[/color]
              ....[color=blue]
              > [Terminology question] What, exactly, is the event handler here?[/color]

              I would say that it is the function you assign to the "onclick"
              property. It is the function that is called to handle the click event.
              [color=blue]
              > Is it myResponse or is it the intermediate step specified in the
              > onclick line?[/color]

              I.e., the latter. The function "myResponse " is just another Javascript
              function, which just happens to be called from an event handler.
              [color=blue]
              > In the latter, your comment about a single event
              > argument is born out. Interestingly >this< is known about in the
              > onclick line (though it's not an argument),[/color]

              "this" is never an argument, since it is not a legal variable name. It
              is a keyword.

              The handler function, assigned to the onclick property (possibly via
              an HTML attribute), is called as a method of the element it belongs to.
              That means that inside the body of the function, the keyword "this" refers
              to the element.

              The function "myResponse " is called as a global function. That means
              that inside its body, the this keyword should refer to the global
              object.
              [color=blue]
              > but it is not known about in myResponse.[/color]

              It should point to the global object (which can also be referred to as
              "window" or "self"). Since the window object doesn't have a nodeName
              property, "this.nodeN ame" is undefined (which is transformed to a string
              to become "undefined" ).

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              Working...