Setting onload and onresize events to window problem

Discussion in 'Javascript' started by johkar, Oct 29, 2006.

  1. johkar

    johkar Guest

    The below script executes fine and sets both divs to equal height,
    however if I try adding onresize also IE has a major problem and
    freezes up. What am I missing here? Note I would like to be able to
    call this script by calling it from the body tag or from an inline
    script (currently commented out below).

    John

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <style type="text/css">
    div {
    border:1px solid #003366;
    padding:7px;
    width:250px;
    float:left;
    margin-left:15px;
    }
    </style>
    <script type="text/javascript">
    function setDivHeights(id1,id2,id3){
    if(document.getElementById){
    var div1 =
    (document.getElementById(id1))?document.getElementById(id1):false;
    var div2 =
    (document.getElementById(id2))?document.getElementById(id2):false;
    var div3 =
    (document.getElementById(id3))?document.getElementById(id3):false;
    if(div1 && div2){
    var max = div1.offsetHeight;
    if(div2.offsetHeight > max)
    max = div2.offsetHeight;
    if(div3 && (div3.offsetHeight > max))
    max = div3.offsetHeight;

    document.getElementById(id1).style.height = max + "px";
    document.getElementById(id2).style.height = max + "px";
    if(div3)
    document.getElementById(id3).style.height = max + "px";
    }
    }
    }
    //window.onload=function(){setDivHeights('div1','div2');}

    </script>
    </head>

    <body onload="setDivHeights('div1','div2')">
    <div id="div1">
    <p>Some Text Some Text Some Text Some Text Some Text Some Text Some
    Text Some Text Some</p>
    </div>
    <div id="div2">
    <p>Some Text Some Text Some Text Some Text Some Text Some Text Some
    Text Some Text Some Text Some Text Some Text Some Text Some Text Some
    Text Some Text</p>
    </div>
    </body>
    </html>
     
    johkar, Oct 29, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    615
    Martin Honnen
    Nov 4, 2004
  2. Tony

    body onresize vs window.onresize

    Tony, Nov 29, 2005, in forum: Javascript
    Replies:
    2
    Views:
    141
  3. David Gravereaux

    window.onresize problem in IE6

    David Gravereaux, Feb 21, 2006, in forum: Javascript
    Replies:
    8
    Views:
    159
    Thomas 'PointedEars' Lahn
    Feb 23, 2006
  4. df
    Replies:
    14
    Views:
    208
    Thomas 'PointedEars' Lahn
    May 23, 2006
  5. yb

    window.onresize slow (firefox)

    yb, Mar 19, 2007, in forum: Javascript
    Replies:
    1
    Views:
    212
    Evertjan.
    Mar 19, 2007
Loading...

Share This Page