views:

274

answers:

4

Hi!

I've got the following code in a website:

 window.onload = resize;
 window.onresize = resize;

 function resize(){
  heightWithoutHeader = (window.innerHeight - 85) + "px"; 
  document.getElementById("haupttabelle").style.height = heightWithoutHeader;
  document.getElementById("navBar").style.height = heightWithoutHeader;
 }

The onresize works fine, but the onload event never fires. I've tried it in Firefox and Chrome and neither of them works.

Thank you for your help and go for the reputation! ;D

+1  A: 

If it's really in that order, it's definitely not going to work. You can't assign a function to an event handler before the function itself is declared.

Syntactic
I've changed the order now but it still doesn't work.
Bernhard V
As Nick Craver said, it would be helpful to know the larger context of this and when it's actually being called.
Syntactic
A: 

Hi,

This will be work when you call the "window.onload" next to the function resize()

VAC-Prabhu
A: 

This works for me, i think your problem is somewhere else:

 function resize(){
  var tester = document.getElementById("tester"),
      html = tester.innerHTML

  tester.innerHTML = html + "resize <br />"
 }  

window.onload = resize;
window.onresize = resize;

you can test it yourself here: http://jsfiddle.net/Dzpeg/2/

are you sure its the only event called onLoad ? Maybe an other onLoad event creates a conflict

meo
+1  A: 

I think what's probably happening here is that your window.onload is being overridden later, check to make sure that it's not via things like <body onload="">

You can check this by alert(window.onload) in your re-size function, to see what's actually attached there.

Nick Craver