By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,644 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

finding position of a mouse click, using Mozilla

P: n/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>
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 ni**@maproom.co.uk
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 : : :: ::::
Jul 23 '05 #2

P: n/a
In message <42********@news.home.net.pl>, Tomasz Cenian <aa*@bb.cc.dd>
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 ni**@maproom.co.uk
Jul 23 '05 #3

P: n/a
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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.