[thelist] reading netscape table height?

JTocher jtocher at discoverysystems.com
Thu Oct 3 12:28:00 CDT 2002


Karen,

Ever so thankful for clearing this up - and, especially grateful for the
programming tips! Am 'self learned' on javascript/CSS and the lovely
combination of the two - mostly from perusing online site documentation
(unfortunately, many are soooo outdated) and dissecting code snippets in
tutorials.

Good to have someone look over my shoulder and point out ways to improve my
code! Wonderful way to learn.

Cheers,
Janice


on 10/3/02 9:29 AM, you wrote:

> jtocher wrote:
>> The following script works fine on IE
>>
>> function tbl_Height(ThisDiv) {
>> if (document.layers){
>> var height = document.layers['txt'+ ThisDiv].document.height + 50;
>> }
>> else if (document.all){
>> var height = document.all['txt'+ThisDiv].clientHeight + 50;
>> }
>> var tbl = window.document.getElementById('tbl');
>> tbl.style.height = height + 'px';
>>
>> but, not on Netscape 6 or above
>
> Janice, it won't work in Netscape 4 either...
>
> There are 3 different browser DOM's you're dealing with here: NN4 uses
> document.layers, IE4 uses document.all (which will work in IE5 too,
> don't know about IE6) and modern browsers (IE5+, NS6+) use
> document.getElementById.
>
> So with your script, the first conditional statement - "if
> (document.layers)..." - will work in Netscape 4 only, but the rest of
> the script won't.  (I'm assuming from what you've asked that you don't
> need NN4 compatibility though.)
>
> To get it working in NS6+ you need to add a 3rd conditional statement
> after the IE4 bit:
>
> else {
> height = document.getElementById('txt'+ThisDiv).style.height + 50;
> }
>
> A couple of notes -- you should avoid using variable names that are
> already names of other elements, attributes, properties, etc.  This
> practice could get you into hot water somewhere along the track.  Also,
> it's nice programming style to declare your variable once at the start
> rather than again and again throughout the code.
>
> so your function now becomes:
>
> function tbl_Height(ThisDiv) {
> var h, tbl;
> if (document.layers){
> h = document.layers['txt'+ ThisDiv].document.height + 50;
> // code to set table height in NN4 would go here
> } else if (document.all) {
> h = document.all['txt'+ThisDiv].clientHeight + 50;
> tbl.style.height = h;
> } else {
> h = parseInt(document.getElementById('txt'+ThisDiv).style.height);
> h += 50;
> tbl = window.document.getElementById('tbl');
> tbl.style.height = h;
> }
> }
>
> Note the use of the parseInt() function when getting the div height, as
> thediv.style.height returns the appended 'px' too.
>
> hth
> Karen
> -------
> Miinx Design & Development
> e :: karen at miinx.com.au
> p :: 0413.880.302
> w :: www.miinx.com.au
>




More information about the thelist mailing list