Sleep
Description
Suspends (sleeps) script execution for a specified timeout or until a passed callback function returns true. This is an efficient way to wait for an event without burning CPU cycles.
Syntax
printing.Sleep(timeout, [callback])
Parameter | Description |
---|---|
timeout | (Number) the timeout in milliseconds |
callback |
[Optional] (Function) the optional pointer to the function to be periodically called
within the Sleep method. When the function returns true, the sleep is canceled. |
Returns true if the sleep was canceled by a callback function.
Example
The following code snippet navigates a frame to a file then prints its content:
<script>
function NavigatePrintFrame(url) {
idFrame.navigate(url);
factory.printing.Sleep(100); // let the navigation start
factory.printing.Sleep(1000 * 60, IsReady); // sleep for 1 minute or until the document is ready
factory.printing.Print(true, idFrame);
}
function IsReady() {
return idFrame.document.readyState == "complete";
}
</script>