Jump to content

Recommended Posts

I'm using javascript to equalise the height of 2 columns so I can place a footer below them.
The script I use works perfectly in IE, it works in Firefox when the page is first loaded, but if the window is resized it doesn't.
Can anyone help?

This is the script I'm using.

[code]function setTall() {
    if (document.getElementById) {
        // the divs array contains references to each column's div element.  
        // Replace 'center' 'right' and 'left' with your own.  
        // Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
        var divs = new Array(document.getElementById('c1'), document.getElementById('c2'));
        
        // Let's determine the maximum height out of all columns specified
        var maxHeight = 0;
        for (var i = 0; i < divs.length; i++) {
            if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
        }
        
        // Let's set all columns to that maximum height
        for (var i = 0; i < divs.length; i++) {
            divs[i].style.height = maxHeight + 'px';

            // Now, if the browser's in standards-compliant mode, the height property
            // sets the height excluding padding, so we figure the padding out by subtracting the
            // old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
            if (divs[i].offsetHeight > maxHeight) {
                divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
            }
        }
    }
}

onload = function() {
    setTall();
}

window.onResize = function() {
    setTall();
}[/code]

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/3507-onresize-not-working-with-firefox/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.