/** 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