How to handle multiple window. onload events simultaneously when referencing other js _ javascript skills

Source: Internet
Author: User
When referencing other js, its js uses the window. onload event. In this case, the onload event of the introduced page may not be executed. How can this problem be solved? When other js is referenced in the following section, its js uses window. onload event. In this case, the onload event of the introduced page may fail to 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
For example, you need to run a variable method.

Function name1 (){......} Function name2 (){......} Var m = "name1"; eval (m + '()'); // run name1 (); m = 'name2'; eval (m + '()'); // run name2 ();

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.