How to handle multiple window.onload events at the same time when referring to other js

  • 2020-03-30 03:50:23
  • OfStack

Sometimes, when referring to other js, its js USES window.onload event. In this case, the onload event of the incoming page may not execute. How to run both? There are other ways to do this other than putting the two together


if(window.onload!=null){ 
eval("theOldFun="+window.onload.toString()); 
window.onload=function(){theOldFun();addReadResource();}; 
}

Eval () function:

Its function is to parse the corresponding string into JS code and run it
Let's say you're running a mutable method


function name1(){ ... } 
function name2(){ ... } 
var m="name1"; 
eval(m+'()');//Run name1 ();
m='name2'; 
eval(m+'()');// run name2();

Related articles: