[Javascript] HTML object's position

Dan Costea costea.dan at ssi-schaefer.ro
Tue Jan 22 07:16:59 CST 2002


> >I work with IE5.5; I have an object somewhere in the page:
> >
> ><IFRAME id="iframeObj" SRC="mytest.html"></IFRAME>
> >
> >How can I find out iframeObj's left and top position?
> >
> >(I tried with: document.all['iframeObj'].style.top but it doesn't work)
>
> Try http://www.xs4all.nl/~ppk/js/index.html?findpos.html
>
> I've never tried it on an IFRAME so I'm not sure if it works. If it does,
> please let me know.
>

It works just fine! Thank you!


the functions I need are:

function findPosX(obj)
{
 var curleft = 0;
 if (document.getElementById || document.all)
 {
  while (obj.offsetParent)
  {
   curleft += obj.offsetLeft
   obj = obj.offsetParent;
  }
 }
 else if (document.layers)
  curleft += obj.x;
 return curleft;
}

function findPosY(obj)
{
 var curtop = 0;
 if (document.getElementById || document.all)
 {
  while (obj.offsetParent)
  {
   curtop += obj.offsetTop
   obj = obj.offsetParent;
  }
 }
 else if (document.layers)
  curtop += obj.y;
 return curtop;
}




More information about the Javascript mailing list