iframe relative mouse position

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • madmike

    iframe relative mouse position

    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.cl ientX + document.body.s crollLeft;
    yMousePos = window.event.cl ientY + document.body.s crollTop;

    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
  • Csaba2000

    #2
    Re: iframe relative mouse position

    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" <mikek@cs.cmu.e du> wrote in message news:cb16b300.0 307160810.37526 5f3@posting.goo gle.com...[color=blue]
    > 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.cl ientX + document.body.s crollLeft;
    > yMousePos = window.event.cl ientY + document.body.s crollTop;
    >
    > 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[/color]


    Comment

    • madmike

      #3
      Re: iframe relative mouse position

      this worked for me.

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

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

      Comment

      Working...