Forum Moderators: open

Message Too Old, No Replies

Find cursor position...

cross browser compatibility

         

fmaz

4:01 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Hi, right now, I'm doing this:

var x = (navigator.appName.substring(0,3) == "Net")? e.pageX : event.x+document.body.scrollLeft;
var y = (navigator.appName.substring(0,3) == "Net")? e.pageY : event.y+document.body.scrollTop;

But many visitor telling me that the position of my info-box is not displayed at the cursor, but higher (so the scroll calculation must be incorrect.

Can some one help me to improve my code please?

Sathallrin

4:52 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Try this:

var ie5 = document.all&&document.getElementById;
var x = ie5? event.clientX : e.clientX;
var y = ie5? event.clientY : e.clientY;

Make sure to call the function with event as a parameter for the onClick. And have it passed in as variable e.

fmaz

2:51 am on Jun 18, 2005 (gmt 0)

10+ Year Member



This code doesn't work at all under FireFox (now nothing work ;p): When the page scroll, the cursor position given is not the position in the document, but in the "screen" or in the "window"

No body have a function that return a X and Y position of the cursor that is cross browser compatible?