View Full Version : [CLOSED]Bug in Element.getXY()

1 Mar 2011, 1:25 PM
It's actually a 3.3.1 bug but I see the same code unchanged in 4.0 so...

This code:
if (el.getBoundingClientRect) {
b = el.getBoundingClientRect();
scroll = fly(document).getScroll();
ret = [Math.round(b.left + scroll.left), Math.round(b.top + scroll.top)];

creates some problems if we have an iframe on a page and want to get coordinates for some elements inside it.

getBoundingClientRect() for an element inside an iframe returns coordinates respective to an iframe's document, not the main document.

But the code in getXY() always add scroll values of the main document to it.
So when the main document is scrolled the coordinates inside an iframe get wrong (and are not constant).

The illustration is here:

It's actually a modified HTMLEditor coupled with an advanced syntax checking service (sorry the interface is not in English).

Check the top-right checkbox below editing area for English language, type in any wrong word, press the button on the form footer or the same button in the toolbar for checking.
Then, when the word get underlined with red, invoke a context menu for that word.

Before the context menu appears you will see an alert with debugging info.

Take a note that if you scroll the main document window down before invoking the context menu the word coordinates get the main window scroll added.

1 Mar 2011, 11:19 PM
I would say that there are a few methods in the Element class that might not work as you'd expect when using iframes. However at this point I don't see us making any changes to this behaviour, the potential for slowing down a lot of the core lib to check for edge cases like this without a great deal of benefit.

Thanks for taking the time to write a detailed report.