How to handle multiple window. onload events and multiple window. onload events at the same time

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.