• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Mouse events in firefox (REALLY)

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Mouse events in firefox (REALLY)

    Trying to convert some interactives in IE to work in FF but problems with mouse events. According to various sources on net onmousedown= or onclick= in Firefox automatically passes the mouse event as 1st argument of the function, then you can or it with the global event to get something you can use in IE or Firefox eg:

    jscript:
    function gete(e)
    {
    ev = e || window.event;
    etc.
    }

    HTML:
    <span id=holly onclick=gete()>etc.

    This does not work, e is reported as having no properties and if gete has explicit arguments you get same passed in IE as Firefox, this event argument that FF is supposed to pass does not exist. I don't find examples from the net work either.

    mousemove does seem to work as stated so I could store last value obtained in that but it seems messy. Any other ideas?

    Cheers
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    #2
    Originally posted by xoggoth View Post
    Trying to convert some interactives in IE to work in FF but problems with mouse events. According to various sources on net onmousedown= or onclick= in Firefox automatically passes the mouse event as 1st argument of the function, then you can or it with the global event to get something you can use in IE or Firefox eg:

    jscript:
    function gete(e)
    {
    ev = e || window.event;
    etc.
    }

    HTML:
    <span id=holly onclick=gete()>etc.

    This does not work, e is reported as having no properties and if gete has explicit arguments you get same passed in IE as Firefox, this event argument that FF is supposed to pass does not exist. I don't find examples from the net work either.

    mousemove does seem to work as stated so I could store last value obtained in that but it seems messy. Any other ideas?

    Cheers
    The event object is indeed passed as the first argument to (e.g.) your onmouseover handler, but that handler is then invoking another function and not passing it along. Basically, when you use inline event handlers, rather than attaching events, the event handler is created as an anonymous function. If you then want to call another function, you have to pass the first parameter along to it.

    So, where you have

    Code:
    <div onmouseover="ton(this)">blah</div>
    the onmouseover attribute has a value which is a function object:

    Code:
    function onmouseover(event) { 
       ton(this); 
    }
    and the "event" parameter isn't being used. Change it to

    Code:
    <div onmouseover="ton(event, this)">blah</div>
    and change your function to

    Code:
    function ton(e, that) {
       var ev = e || window.event;
       // do stuff with "that"
    }
    and it should work.

    BTW this isn't a Firefox thing; IE also does the anonymous function thing internally, but because it doesn't pass any arguments, it isn't always apparent. You can see this if you go to http://www.gatekeeperel.co.uk/intera.../keyyesno.html and then type

    Code:
    javascript:alert(document.getElementById("scroll").onmouseover)
    Last edited by NickFitz; 27 November 2008, 15:20.

    Comment


      #3
      Actually, I've just noticed that

      Originally posted by NickFitz View Post
      Code:
      <div onmouseover="ton(event, this)">blah</div>
      will, on IE, find the global event property of window and pass that along on IE, so rendering the first line of the function redundant.

      However, I'm not certain what would happen on Opera, Safari or Chrome: it might be better to use

      Code:
      <div onmouseover="ton(arguments[0], this)">blah</div>
      to be on the safe side.

      Comment


        #4
        Thanks again nick, that works, on to the next problem!
        bloggoth

        If everything isn't black and white, I say, 'Why the hell not?'
        John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

        Comment

        Working...
        X