Deep understanding of JS addloadevent function _javascript Skills

Source: Internet
Author: User

First is the code listing for the Addloadevent function:

function Addloadevent (func)
{
 var oldonload=window.onload;
 if (typeof window.onload!= ' function ')
 {
  Window.onload=func
 }
 else
 {
  window.onload=function ()
  {
   oldonload ();
   Func ();}}

Understood is:

1. Deposit the value of the existing Window.onload event handler function into the variable oldonload;

2. If you have not yet bound any function on this handler function, add the new function to it as usual;

3. If you have already bound some functions on this handler, append the new function to the end of the existing instruction.

This function is very practical, especially when the code becomes more and more complex, no matter how many functions you intend to perform on the page, just write one more statement to get it done.

The above JS addloadevent function is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.