window.event.x

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dipalichavan82
    New Member
    • Feb 2008
    • 41

    window.event.x

    i m wrinting javascript. on button click i am calling a javascript function that returns (x,y) coordinate of point where i clicked.
    i used
    window.event.x and window.event.y

    it works fine in IE but not in mozila ..why so
    any solution
    thnx
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    #1- there is no window.event in firefox.
    #2- there is no x property of an event object. try screenX instead.

    Comment

    • zaphod42
      New Member
      • Oct 2008
      • 55

      #3
      Code:
      mouseX=function(evt){
      return(evt?(evt.pageX?evt.pageX:evt.clientX):(window.event.pageX?window.event.pageX:window.event.clientX))+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft)
      }
      mouseY=function(evt){
      return(evt?(evt.pageY?evt.pageY:evt.clientY):(window.event.pageY?window.event.pageY:window.event.clientY))+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)
      }

      Comment

      • Rsmastermind
        New Member
        • Sep 2008
        • 93

        #4
        Originally posted by rnd me
        #1- there is no window.event in firefox.
        #2- there is no x property of an event object. try screenX instead.
        Sorry to say but there is window.event in the firefox I had done and executed the code.The code written above by zaphod42 will work fine instead of the browser's behaviour.

        The second solution provided by you is ok.

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          Originally posted by Rsmastermind
          Sorry to say but there is window.event in the firefox I had done and executed the code.The code written above by zaphod42 will work fine instead of the browser's behaviour.
          I can personally assure you there is no window.event in firefox (unless you create one).

          yes the code does work fine. thats because the firefox part doesn't use window.event but the intrinsic event argument, in this case named evt.
          i know it's confusing, so lets break it down:


          in the code:
          Code:
           mouseY=function(evt){
           return(evt?(evt.pageY?evt.pageY:evt.clientY):(wind  ow.event
          it asks (evt?)
          if yes ( an event object was passed to the function, as in firefox), it returns evt.pageY or evt.clientY.

          if (evt?) results in no, it means no argument was passed, as in IE.
          it then returns window.event.pa geY or window.event.cl ientY

          so to sum: ie uses the window.event part, and firefox uses the argument evt part.

          i hope this helps shed some light on the two confusing event models.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            This similar code will be a little easier to understand.

            Comment

            Working...