la*********@gmail.com wrote:
Tested in IE7 and FF2. [...]
window.parent.frames["lft"].document.getElementById('r2').style.height=(docum ent.getElementById('r2'i).offsetHeight)
+ 'px';
Everything works perfectly, cell gets resized, BUT then I read back
the height of both cells, here:
alert(document.getElementById('r2').offsetHeight + ' - ' +
window.parent.frames["lft"].document.getElementById('r2').offsetHeight );
In FireFox it returns 17 and 17 pixels, perfect. But IE7 returns 17
and 20 pixels (17 for the original cell, 20 for the newly resized
cell)! And they don't align! Why?
The proprietary `offsetHeight' property value is not necessarily the same as
the CSS `height' property value. When you set the CSS `height' property on
the table cell in MSHTML, you define the client area height (not to be
confused with clientHeight). The 3 additional pixels account for the
padding around the client area and the borders around that. It can be
tested easily without a directly scripted assignment to the CSS property (IE
7.0.5730.11 CSS1Compat Mode, on WinXP SP3):
javascript
:document.body.innerHTML = '<table><tr><td style="height:4px;
padding:2px; border:1px solid black;
line-height:0"> </td></tr></table>');
window.alert(document.getElementsByTagName("td")[0].offsetHeight)
(Or you can create a static test case that only accesses offsetHeight.)
The alert window would shows 10 here, because
offsetHeight := height + padding + borders = 4 + 2*2 + 2*1 = 10.
(If line-height is not declared, it shows 22 for line-height:normal here; YMMV.)
See also <http://msdn.microsoft.com/en-us/library/ms530302(VS.85).aspx>.
Why do the browsers act differently?
Gecko implements the standards-compliant W3C CSS Box Model; IE implements
the proprietary MSHTML box model. Deprecated HTML formatting attributes and
BackCompat/Quirks Mode may also interfere.
And how could I compensate the difference?
Knowing what you are using, and computing it accordingly.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>