iframe relative mouse position

M

madmike

Hi,


I have an iframe with some javascipt that gets the mouse x and y
position like this:
//inside the iframe's onmousemove call back funciton
xMousePos = window.event.clientX + document.body.scrollLeft;
yMousePos = window.event.clientY + document.body.scrollTop;

This gets the x and y position inside the iframe. But what I want is
the x and y position of the parent window, not the screen like
screenX. Is there any easy way to get parentX and parentY or to get
the offset x and y of the iframe relitive to the parent from inside
the iframe?


thanks in advance,
mike
 
C

Csaba2000

The way I've done this in the past (if memory serves) is to find the element containing the IFrame and then percolate
up using .offsetParent

Csaba Gabor
 
M

madmike

this worked for me.

// get the position relitive to the entire window
var el =parent.frames[FRAME_NAME].frameElement.offsetParent;
var x = 0, y = 0;

while (el)
{
x += el.offsetLeft;
y += el.offsetTop;
el = el.offsetParent;
}
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top