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

Getting the current cursor position using clientX,clientY

P: n/a
I have an html element (a link) with an onclick handler which opens a
popup window, and would like to position that window at the coordinates
where the element appears on the page. I have installed a
document.onclick event handler which saves the eventX and eventY
values, then use those values to set the window top/left coordinates.

The problem is that the eventX and eventY values always seem to be the
previous coordinates, not the current ones. In other words, the first
time that I click the element, no coordinates have been set. The next
time I click the element, the coordinates from the first click have
been saved. Because there are multiple clickable elements on the page,
the effect is that the popup window is always opening at the previous
cursor position rather than the current position.

It seems like my document.onclick event handler is being called after
the onClick handler defined for the particular HTML element.

Can anyone provide info on how I can detect the current cursor position
before the element-specific onClick handler executes?
Thanks!

-Dave H.

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dave Hammond wrote:
I have an html element (a link) with an onclick handler which opens a
popup window, and would like to position that window at the coordinates
where the element appears on the page. I have installed a
document.onclick event handler which saves the eventX and eventY
values, then use those values to set the window top/left coordinates.


Have a read of:
<URL:http://evolt.org/article/Mission_Impossible_mouse_position/17/23335/index.html>

and:

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

--
Fred
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.