Page 1 of 1

onResize event crashes IE, probably easy to a JavaScript'er

Posted: Sat Sep 04, 2004 7:37 am
by Chris Corbyn
Hi,

Can anyone see a better way to do this....?

I'm trying to make a table height that lives inside a table cell change dynamically if the cell height changes.

I have this code in my JS file.

Code: Select all

function doNewHeight(tableId, cellId) {
    document.getElementById(tableId).style.height = document.getElementById(cellId).offsetHeight
}
and then something like this in my html

Code: Select all

<table onResize="doNewHeight('table1','cell1')">
    <tr>
        <td id="cell1">
            <table id="table1">
                <tr>
                    <td>Bunch of pictures</td>
                </tr>
            </table>
        </td>
    </tr>
</table>
Doesn't work well in either browser (NS7 or IE6). In IE as soon as you resize the window IE stops responding. In NS7 when you resize it does its job but everytime you resize again it adds to the height so the height just keeps growing.

If anybody can see another way around this I'd be very grateful.

Thanks :-)

Posted: Sat Sep 04, 2004 9:37 am
by feyd
tell the page to reload, instead of "adjusting" the height.

Posted: Sat Sep 04, 2004 9:47 am
by Chris Corbyn
Hadn't thought of that. I'll do it but it could be bit annoying maybe for some people. Better than a buggy script though.

Thanks for the tip :-)

Posted: Sat Sep 04, 2004 9:53 am
by feyd
NS for a long time has had a problem with the resize handler, so instead of trying to adjust the content, it's often easier to tell it to reload the page to fix itself.

It can be suggested that you may want to rethink your design if it requires these measures though. ;)