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
Release: 2016-05-16 16:37:52
Original
1028 people have browsed it

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();}; 
}
Copy after login

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();
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template