Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Works in IE but not Firefox 1

Status
Not open for further replies.

tiamat2012

Programmer
Joined
Dec 12, 2004
Messages
144
Location
US
Hey guys, I've got a javascript that only works in IE and not javascript, anyone know why?

js
Code:
  	window.onload=function(){

     if(document.getElementsByTagName){

          matchHeight();

     }

		 } 
		
		matchHeight=function(){

         var divs,contDivs,maxHeight,divHeight,d;

         // get all <div> elements in the document

         divs=document.getElementsByTagName('div');

         contDivs=[];

         // initialize maximum height value

         maxHeight=0;

         // iterate over all <div> elements in the document

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

              // make collection with <div> elements with class attribute 'container'

              if(/\bcontainer\b/.test(divs[i].className)){

                    d=divs[i];

                    contDivs[contDivs.length]=d;

                    // determine height for <div> element

                    if(d.offsetHeight){

                         divHeight=d.offsetHeight;

                    }

                    else if(d.style.pixelHeight){

                         divHeight=d.style.pixelHeight;

                    }

                    // calculate maximum height

                    maxHeight=Math.max(maxHeight,divHeight);

              }

         }

         // assign maximum height value to all of container <div> elements

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

              contDivs[i].style.height=maxHeight;

         }

    }

and then there are three divs that I apply this to like:

<div id="lmenu" class="container">
<div id="maincontent" class="container">
<div id="rbanner" class="container">

any ideas? you can see the actual pages at
-Kerry
 
Does changing this:

Code:
matchHeight=function(){

to this:

Code:
function matchHeight(){

make any difference?

I have no idea why you'd ever define a global function like that, to be honest.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Also, how does it not work? What does it mot do? Have you tried putting in any alert statements to see if it's ever called? Have you tried using the Venkman debugger for Firefox to try diagnosing this or narrowing it down? If so, what did you find? If not, suggest downloading it - it's not bad.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Sorry for the really long delay, I went on a trip and there was no computer I could get to that had internet.

I tried doing the change (recommended in your first reply) and it still didn't work.

How would I make a private function (I don't see how it's global?)

I tried the debugger but I have Firefox 1.5 and it doesn't support it :\.

The function extends columns because my faux columns didn't work, and no one has helped me in the CSS forum with that so this is my alternate route.

-Kerry
 
Ok found it, you fixed it again.

took me a bit to learn, but I found the problem

Code:
for(var i=0;i<contDivs.length;i++){

     contDivs[i].style.height=maxHeight;

}

conDivs.style.height is a string, not an integer. it wouldn't allow the change, so I added the code

Code:
if(maxHeight < 764)
{
     changeto = "100%";
} else
{
     changeto = maxHeight + "px";
}
				 
for(var i=0;i<contDivs.length;i++){
				 

     contDivs[i].style.height = changeto;

}

in and it worked fine, thank you so much for your time!
 
No problem - good to see you cracked it!

Firefox is definately more strict on having the unit specifier in place. I've fallen foul of that one before, too.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top