Getting the current cursor position using clientX,clientY

D

Dave Hammond

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.
 
F

Fred Oz

Dave said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top