JavaScript event [removed] not triggered

后端 未结 8 1074
无人及你
无人及你 2021-02-01 01:15

I\'ve got the following code in a website:

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

 function resize(){
  heightWithoutHeader = (window.innerHeight -         


        
8条回答
  •  时光取名叫无心
    2021-02-01 01:39

    This answer is for those who came here because their window.onload does not trigger.

    I have found that for the following to work

    window.onload = myInitFunction;
    

    or

    window.addEventListener("load", myInitFunction);
    

    the referred function (myInitFunction in this case) must reside (or be defined) within the same onload test

    But this will work:

    
      
        onload test
        
    
        
    
        
    
      
      
        onload test
      
    
    

    And this will work (since we only have one onload test

    If you for some reason have two

提交回复
热议问题