finding position of a mouse click, using Mozilla

Discussion in 'Javascript' started by Nick Wedd, Mar 1, 2005.

  1. Nick Wedd

    Nick Wedd Guest

    I have this
    <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
    <IMG border=0 height=66 width=292 src="gifs/top.gif">
    </DIV>
    which works in IE. myhandler gets called with the coordinates of where
    the mouse was clicked relative to the <HTML>, and I know where my DIV
    is, so I can calculate which part of the image was clicked on.

    But with Mozilla, I can't use event.x and event.y, only event.screenX
    and event.screenY. These are relative to the whole screen, and so are
    affected by the positioning of the browser window and the amount of
    browser chrome, so I can't translate them to the frame of my image.

    Is there a simple way to deal with this? A Google search leads me to
    pages like http://www.mozilla.org/docs/events.html which I am not able
    to understand.

    The best I can come up with is to create a bunch of empty ("visible" but
    transparent) layers that sit in front of my "canopy" layer and catch the
    mouse clicks.

    Nick
    --
    Nick Wedd
     
    Nick Wedd, Mar 1, 2005
    #1
    1. Advertising

  2. Nick Wedd napisał(a):
    > I have this
    > <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
    > <IMG border=0 height=66 width=292 src="gifs/top.gif">
    > </DIV>


    You surely missed
    event.clientX, event.clientY.

    Do not use event.x - its obsolete and IE only.


    --
    tomasz cenian tcenian at wa dot home dot pl
    :::: :: : : http://cenian.boo.pl : : :: ::::
     
    Tomasz Cenian, Mar 1, 2005
    #2
    1. Advertising

  3. Nick Wedd

    Nick Wedd Guest

    In message <42244bff$>, Tomasz Cenian <>
    writes
    >Nick Wedd napisa0 >> I have this
    >> <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
    >> <IMG border=0 height=66 width=292 src="gifs/top.gif">
    >> </DIV>

    >
    >You surely missed
    >event.clientX, event.clientY.
    >
    >Do not use event.x - its obsolete and IE only.


    Great! Thanks very much for the advice.

    Nick
    --
    Nick Wedd
     
    Nick Wedd, Mar 1, 2005
    #3
  4. Nick Wedd

    RobG Guest

    Nick Wedd wrote:
    > I have this
    > <DIV id="canopy" onClick="myhandler(event.x,event.y); return false;">
    > <IMG border=0 height=66 width=292 src="gifs/top.gif">
    > </DIV>
    > which works in IE. myhandler gets called with the coordinates of where
    > the mouse was clicked relative to the <HTML>, and I know where my DIV
    > is, so I can calculate which part of the image was clicked on.
    >
    > But with Mozilla, I can't use event.x and event.y, only event.screenX
    > and event.screenY. These are relative to the whole screen, and so are
    > affected by the positioning of the browser window and the amount of
    > browser chrome, so I can't translate them to the frame of my image.
    >
    > Is there a simple way to deal with this? A Google search leads me to
    > pages like http://www.mozilla.org/docs/events.html which I am not able
    > to understand.


    The section of the Mozilla site you were after is:

    *DOM Reference*:
    <URL:http://www.mozilla.org/docs/dom/domref/>

    *Event Reference*

    <URL:http://www.mozilla.org/docs/dom/domref/dom_event_ref.html#998197>

    Where you will find references to W3C DOM properties clientX/Y
    and screenX/Y and the older, non-W3C layerX/Y, pageX/Y.

    If you are doing stuff with coordinates, the "Viewport" link at
    quirksmode.org is an invaluable reference:

    <URL:http://www.quirksmode.org/index.html>


    --
    Rob
     
    RobG, Mar 1, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davisro
    Replies:
    2
    Views:
    1,316
    Jim Corey
    Apr 23, 2004
  2. Max
    Replies:
    7
    Views:
    9,123
  3. tom arnall
    Replies:
    6
    Views:
    1,283
    Ian Shef
    Jan 18, 2007
  4. James Black
    Replies:
    0
    Views:
    403
    James Black
    May 28, 2006
  5. Daniish
    Replies:
    2
    Views:
    245
    Thomas 'PointedEars' Lahn
    Jun 13, 2008
Loading...

Share This Page