When the document is ready, the function is called

Source: Internet
Author: User

/** transfer function to Whenready (), the function will trigger the registration function as a method call to the Document object *domcontentloaded, Readystaatechange, or the Load event when it is fully parsed and the operation is ready *   Once the document is ready, all functions will be called, and any function passed to Whenread () will immediately call ***/var whenready= (function () {//This function returns Whenreadyvar funcs=[]; When the event is obtained, the function to run Var ready =false; When the event handler is triggered, switch to true//when the document is ready, call the event handler function handler (e) {///If it has been run once, just return to if (ready) return;// If the ReadyStateChange event occurs//But its status is not complete, then the document is not ready if (e.type = = = "ReadyStateChange" && document.readystate! = = "complete") return;//Run all registration functions//Note each time to calculate funcs.length//in case the call of these functions may result in the registration of more functions for (var i = 0; i < funcs.length; i++) {Fu Ncs[i].call (document);} Now set the Ready ID to true and remove all functions ready = True;funcs = [];} Register handlers for any events that are accepted if (Document.addeventlistener) {Document.addeventlistener ("Domcontentload", Handler,false); Document.addeventlistener ("ReadyStateChange", Handler,false) Document.addeventlistener ("Load", Handler,false)} else if (document.attachevent) {document.attachevent ("onreadystatechange", Handler); Window.attachevent ("onload", handler);} Back to Whenready ()())

  

When the document is ready, the function is called

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.