How to handle multiple window. onload events and multiple window. onload events at the same time
Sometimes when other js is referenced, its js uses the window. onload event. In this way, the onload event of the introduced page may not be executed. How can we run both of them? Besides writing two methods together, there are other methods.
If (window. onload! = Null) {eval ("theOldFun =" + window. onload. toString (); window. onload = function () {theOldFun (); addReadResource ();};}
Functions of eval:
Its function is to parse the corresponding string into JS Code and run it. For example, you need to run a variable method now.Function name1 (){......} Function name2 (){......} Var m = "name1"; eval (m + '()'); // run name1 (); m = 'name2'; eval (m + '()'); // run name2 ();
In js, how does one deal with the conflict of the same name in the windowonload event of multiple pages?
There can only be one window. onload event on the page. solution:
1. Merge 2. js and 3. js into a window. onload event.
2. Change window. onload to $ (function () {...}) of jQuery (){.....})
Two javascript functions can be blocks, both of which are windowonload. How can I make multiple functions run normally on one page?
Execute a function in the window. onload event.
This function calls other functions
It is best to put javascript at the end of the page