Home >Web Front-end >JS Tutorial >How to handle multiple window.onload events at the same time when referencing other js_javascript skills

How to handle multiple window.onload events at the same time when referencing other js_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:37:521024browse

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();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn