Safari window.onload() workaround needed

Discussion in 'Web Design and Development' started by happy123, Sep 19, 2006.

  1. happy123 macrumors newbie

    Joined:
    Sep 8, 2006
    #1
    Hi. I am using javascript with window.onload() which Safari is not very happy about. I'm new to coding to handle mac issues. Does anyone have a workaround. Code below ...

    matchColumns=function(){

    var divs,contDivs,maxHeight,divHeight,d;
    divs=document.getElementsByTagName('div');
    contDivs=[];
    maximumHeight=0;

    for(var i=0;i<divs.length;i++){

    if((divs.id=="grouping")||(divs.id=="textbar")||(divs.id=="ads")||(divs.id=="content"))
    {
    d=divs;
    contDivs[contDivs.length]=d;

    if(d.offsetHeight)
    {
    divHeight=d.offsetHeight;
    }
    else if(d.style.pixelHeight)
    {
    divHeight=d.style.pixelHeight;
    }
    maximumHeight=Math.max(maximumHeight,divHeight);
    }
    }
    contDivs[0].style.height=(maximumHeight + 20) + "px";
    contDivs[1].style.height=(maximumHeight-10) + "px";
    contDivs[2].style.height=maximumHeight + "px";
    contDivs[3].style.height=(maximumHeight-20) + "px";
    }


    window.onload=function()
    {
    if(document.getElementsByTagName){
    matchColumns();
    }
    }
     
  2. Thom_Edwards macrumors regular

    Joined:
    Apr 11, 2003
    #2
    first, i'm not sure why you're doing
    Code:
    matchColumns=function()
    maybe try...
    Code:
    function matchColumns()
    Then...
    Code:
    function init()
    {
    if(document.getElementsByTagName){
    matchColumns();
    }
    }
    and finally
    Code:
    window.onload = init();
    your functionname = function() works, but i don't understand why you wouldn't use the (much?) more common function functionname() syntax. yours is legal and works in firefox and ie7 , i just haven't seen it used much. is there any reason why you chose that way?

    i did a little googling on this beacuse i just wondered what others had to say about it. apparently there are several other options out there if you do a little searching. i even found one page (http://haacked.com/archive/2006/04/06/StopTheWindow.OnloadMadness.aspx) that makes my solution look "arrogant" according to the author. apparently i'm stealing events...

    anyway, i'm nowhere close to a mac, but that is probably how i would do it.
     

Share This Page