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

iframe relative mouse position

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"madmike" <mi***@cs.cmu.edu> wrote in message news:cb**************************@posting.google.c om...
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

Jul 20 '05 #2

P: n/a
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;
}
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.