adding to [removed] event?

后端 未结 4 1530
猫巷女王i
猫巷女王i 2020-11-27 12:33

I\'m wondering how to add another method call to the window.onload event once it has already been assigned a method call.

Suppose somewhere in the script I have this

4条回答
  •  失恋的感觉
    2020-11-27 12:58

    This might not be a popular option, but sometimes the scripts end up being distributed in various chunks, in that case I've found this to be a quick fix

    if(window.onload != null){var f1 = window.onload;}
    window.onload=function(){
        //do something
    
        if(f1!=null){f1();}
    }
    

    then somewhere else...

    if(window.onload != null){var f2 = window.onload;}
    window.onload=function(){
        //do something else
    
        if(f2!=null){f2();}
    }
    

    this will update the onload function and chain as needed

提交回复
热议问题