468,243 Members | 1,974 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,243 developers. It's quick & easy.

Getting the current cursor position using clientX,clientY

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
1 9752
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.

Similar topics

3 posts views Thread by Helmut | last post: by
10 posts views Thread by Danny | last post: by
4 posts views Thread by Jay | last post: by
4 posts views Thread by Jonne | last post: by
4 posts views Thread by Sid S. | last post: by
2 posts views Thread by ton | last post: by
3 posts views Thread by Wuggles | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.