Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getBoxObjectFor deprecated

71 views
Skip to first unread message

aren...@fdn.fr

unread,
Mar 4, 2008, 1:46:29 PM3/4/08
to
Hi,
I need, from firefox chrome, to get screen position of an element in a web
page (to show a popup to a position dependent of that element). Therefore, I
use:

var doc = element.ownerDocument;
var x = element.getBoundingClientRect().right
+ doc.getBoxObjectFor(doc.documentElement).screenX
+ doc.documentElement.scrollLeft;

and I get right border position.

but firefox3 outputs in console:

> Warning: Use of getBoxObjectFor() is deprecated. Try to use
> element.getBoundingClientRect() if possible.

Problem is getBoundingClientRect will not get screenX. Should I still use
getBoxObjectFor even if deprecated for html elements, or is there anothery way
to get screen position of an element ?

thanks

Neil

unread,
Mar 5, 2008, 6:42:36 AM3/5/08
to
aren...@fdn.fr wrote:

>Problem is getBoundingClientRect will not get screenX. Should I still use getBoxObjectFor even if deprecated for html elements, or is there anothery way to get screen position of an element ?
>
>

Are you opening the popup as a result of a mouse event? Perhaps you
could use the screen and client coordinates of the mouse to calculate
the screen position of the element.

--
Warning: May contain traces of nuts.

Neil Deakin

unread,
Mar 5, 2008, 7:54:40 AM3/5/08
to
aren...@fdn.fr wrote:
> Hi,
> I need, from firefox chrome, to get screen position of an element in a web
> page (to show a popup to a position dependent of that element). Therefore, I
> use:
>
> var doc = element.ownerDocument;
> var x = element.getBoundingClientRect().right
> + doc.getBoxObjectFor(doc.documentElement).screenX
> + doc.documentElement.scrollLeft;
>
> and I get right border position.
>

It would be better to just use the menupopup's openPopup method which
can position popups relative to other elements for you. The following
opens and aligns a popup with the right edge of an element:

popup.openPopup(element, "end_before");

aren...@fdn.fr

unread,
Mar 5, 2008, 9:29:50 AM3/5/08
to

Thanks,
at first, I did not want to use openPopup because I want the popup to be
"inside" element, and there is no position argument that can do that.

----------------------
| |
| element |
| _____|
|_______________|____| <- popup

But I had not noticed aX and aY arguments to that function. So now, I use:

popup.openPopup(element, "end_after", 0 - popupwidth);

I get popupwidth in popupshowing event first time popup appears.

Thanks for your help

arno

0 new messages