Web site templates - 286 Part III . Document Objects Reference chapter.)
286 Part III . Document Objects Reference chapter.) Multiple timers can run concurrently and are completely independent of each other. While the primary functionality of the setTimeout()method is the same in both NN and IE, each browser offers some extra possibilities depending on the way you use parameters to the method. For simple invocations of this method, the same parameters work in all browsers that support the method. I first address the parameters that all browsers have in common. The expression that comprises the first parameter of the method window.setTimeout() is a quoted string that can contain either a call to any function or method or a standalone JavaScript statement. The expression evaluates after the time limit expires. Understanding that this timeout does not halt script execution is very important. In fact, if you use a setTimeout() method in the middle of a script, the succeeding statements in the script execute immediately; after the delay time, the expression in the setTimeout()method executes. Therefore, I ve found that the best way to design a timeout in a script is to plug it in as the last statement of a function: Let all other statements execute and then let the setTimeout()method appear to halt further execution until the timer goes off. In truth, however, although the timeout is holding, the user is not prevented from performing other tasks. And after a time- out timer is ticking, you cannot adjust its time. Instead, clear the timeout and start a new one. If you need to use setTimeout()as a delay inside a function, break the function into two parts, using the setTimeout() method as a bridge between the two functions. You can see an example of this in Listing 16-26, where IE needs a little delay to finish opening a new window before content can be written for it. If it weren t for the required delay, the HTML assembly and writing would have been accomplished in the same function that opens the new window. It is not uncommon for a setTimeout()method to invoke the very function in which it lives. For example, if you have written a Java applet to perform some extra work for your page and you need to connect to it via LiveConnect, your scripts must wait for the applet to load and carry out its initializations. While an onLoadevent handler in the document ensures that the applet object is visible to scripts, it doesn t know whether the applet has finished its initializations. A JavaScript function that inspects the applet for a clue might need to poll the applet every 500 milliseconds until the applet sets some internal value indicating all is ready, as shown here: var t function autoReport() { if (!document.myApplet.done) { t = setTimeout( autoReport() ,500) } else { clearTimeout(t) // more statements using applet data // } } windowObject.setTimeout()
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.