Window. onload User Guide _ javascript skills

Source: Internet
Author: User
We often use window. onload to process pages. when page loading is complete, we will do something. But this window. onload is the completion of page loading, even including images. next we will discuss in detail the window. onload usage the javascript script code in the webpage can be executed only after the document is loaded. Otherwise, the object cannot be obtained. to avoid this situation, you can use either of the following methods:

1. Place the script code at the low end of the web page. when running the script code, you can ensure that the object to be operated has been loaded.
2. run the script code through window. onload.

The first method is messy (recommended in fact). we often need to place the script code in a more appropriate place, so the window. onload method is a better choice. Window. onload is an event that is triggered after the document is loaded. you can register the event processing function for this event and place the script code to be executed in the event processing function, therefore, you can avoid getting objects. Let's take a look at a code example:

      
   Window. onload usage

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.