Home >Web Front-end >JS Tutorial >How to handle multiple window.onload events at the same time when referencing other js_javascript skills
Sometimes when referencing other js, its js uses the window.onload event. In this case, the onload event of the imported page may not be executed. How can I run both? In addition to the method of writing the two together, there are other methods
if(window.onload!=null){ eval("theOldFun="+window.onload.toString()); window.onload=function(){theOldFun();addReadResource();}; }
The role of the eval() function:
Its function is to parse the corresponding string into JS code and run it
For example, you now want to run a variable method
function name1(){……} function name2(){……} var m="name1"; eval(m+'()');//运行name1(); m='name2'; eval(m+'()');//运行name2();