assigning event with attachEvent instead of onmouseover

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

    assigning event with attachEvent instead of onmouseover

    Hello,

    I'm having difficulty using attachEvent instead of simply assigning to
    mouseover in my object Sample03. When i use myImage.onmouse over =
    this.showmouseo ver(); in the following all works fine, if I replace it by
    myImage.attachE vent('onmouseov er',this.showmo useover()); I get for the
    alert(this.id) "undefined" and not "gwlogo"

    <html>
    <head>
    </head>
    <SCRIPT language="javas cript" type="text/javascript">
    var Sample03 = function(){
    this.Property01 = "Prop01";
    var myImage = document.getEle mentById("gwlog o");
    myImage.onmouse over = this.showmouseo ver();
    //myImage.attachE vent('onmouseov er',this.showmo useover());
    }
    Sample03.protot ype.showmouseov er = function()
    {
    var _this = this;
    return(
    function(e){
    alert(this.id);
    alert(_this.Pro perty01);
    })
    }
    window.onload=f unction(){
    var mySample = new Sample03();
    }

    </SCRIPT>
    <body>
    <img src="http://localhost/winxp.gif" id="gwlogo">
    </body>
    </html>

    Thank you for your assistance.











  • Holger Jeromin

    #2
    Re: assigning event with attachEvent instead of onmouseover

    webgour schrieb am 10.06.2008 17:01:
    I'm having difficulty using attachEvent instead of simply assigning to
    mouseover in my object Sample03. When i use myImage.onmouse over =
    this.showmouseo ver(); in the following all works fine, if I replace it by
    myImage.attachE vent('onmouseov er',this.showmo useover()); I get for the
    alert(this.id) "undefined" and not "gwlogo"


    "The event handling function is referenced, not copied, so the this
    keyword always refers to the window and is completely useless."

    --
    Mit freundlichen Grüßen
    Holger Jeromin

    Comment

    • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

      #3
      Re: assigning event with attachEvent instead of onmouseover

      webgour escribió:
      I'm having difficulty using attachEvent instead of simply assigning to
      mouseover in my object Sample03. When i use myImage.onmouse over =
      this.showmouseo ver(); in the following all works fine, if I replace it by
      myImage.attachE vent('onmouseov er',this.showmo useover()); I get for the
      alert(this.id) "undefined" and not "gwlogo"
      Unless it's just an exercise, I suggest you grab a third-party library
      or framework to attach events. Apart from the headaches it'll save, it
      won't be IE only. I've often used the code described here (find the
      "downloadab le version" link):


      <SCRIPT language="javas cript" type="text/javascript">
      The language attribute is deprecated.


      --
      -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
      -- Mi sitio sobre programación web: http://bits.demogracia.com
      -- Mi web de humor al baño María: http://www.demogracia.com
      --

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: assigning event with attachEvent instead of onmouseover

        Holger Jeromin wrote:
        webgour schrieb am 10.06.2008 17:01:
        >I'm having difficulty using attachEvent instead of simply assigning to
        >mouseover in my object Sample03. When i use myImage.onmouse over =
        >this.showmouse over(); in the following all works fine, if I replace it by
        >myImage.attach Event('onmouseo ver',this.showm ouseover()); I get for the
        >alert(this.i d) "undefined" and not "gwlogo"
        >

        >
        "The event handling function is referenced, not copied, so the this
        keyword always refers to the window and is completely useless."
        See also:




        PointedEars
        --
        Prototype.js was written by people who don't know javascript for people
        who don't know javascript. People who don't know javascript are not
        the best source of advice on designing systems that use javascript.
        -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

        Comment

        • RobG

          #5
          Re: assigning event with attachEvent instead of onmouseover

          On Jun 11, 1:44 am, Holger Jeromin <news03_2...@ka tur.dewrote:
          webgour schrieb am 10.06.2008 17:01:
          >
          I'm having difficulty using attachEvent instead of simply assigning to
          mouseover in my object Sample03. When i use myImage.onmouse over =
          this.showmouseo ver(); in the following all works fine, if I replace it by
          myImage.attachE vent('onmouseov er',this.showmo useover()); I get for the
          alert(this.id) "undefined" and not "gwlogo"
          >

          >
          "The event handling function is referenced, not copied, so the this
          keyword always refers to the window and is completely useless."
          The line above that on Quirksmode is not quite correct, it says (in
          regard to the IE event model):

          "Events always bubble, no capturing possibility."


          When it should say:

          "Events *only* bubble..."


          Not all events bubble, and some events that bubble in other browsers
          do not bubble in IE (such as the change event for form elements).


          --
          Rob

          Comment

          Working...