Global GuideLine Home HTML Tutorial JavaScript Tutorial SQL Tutorial CSS Tutorial SEO Tutorial XML Tutorial XSLT Tutorial Articles Tutorial Interview Questions and Answers Guide Jobs GuideLine Bookmark With Google Bookmark With Yahoo Bookmark With FaceBook Bookmark With Live Follow @GlobalGuideLine on Twitter Bookmark Global GuideLine
JavaScript with SetTimeOut, JavaScript Tutorial, Global Guide Line Technology.
Bookmark this webpage. Bookmark: JavaScript with SetTimeOut, JavaScript Tutorial Global Guideline is UNITED STATES's favorite website

      Home                    

Basic JavaScript Guide.
 JScript Introduction.            
 JScript Why?                       
 JScript Recognitions.          
 JScript onMouseover.         
 JScript with Buttons.           
 JScript Alerts.                     
 JScript Variables.               
 JScript Operators.               
 JScript Functions.               
 JScript Prompts.                 
 JScript Conditions.             
 JScript Validations.            
 JScript Confirmation Boxes.
 JScript Browser Detection.  
 JScript Redirection.            
 JScript on Links.                 
 JScript Switch.                    
 JScript Loops.                     
 JScript Events.                    
 JScript Exception Handling.
 JScript Reserve Characters. 
 JScript with Objects.            
 JScript Math Object.           
 JScript using Dates.             
 JScript using String.            
 JScript using Arrays.            
 JScript Operations.              
 JScript Handling Cookies.   
 JScript in Mapping.             
 JScript Time Out.
 JScript Summary.                

Learn JavaScript with Examples
Learn JavaScript with hundred of short examples with code and output.
Complete_JScript_Examples.php

JScript Interview Questions & Answers
Learn JavaScript by thousands of Interview Questions & Answers.
JavaScriptQuestions/index.php

JavaScript Tutorial >> JavaScript SetTimeOut.


     Back             Next     





In JavaScript with setTimeOut function, we have to remember that JavaScript execution is *not* stopped. So even though we are setting an event to take place in the future, our script continues to run. So our while loop will keep executing and changing the images, there is no pause.

Creating time delays with SetTimeOut in JavaScript

There are two ways of creating time delays in JavaScript. The first is more simple and will simply wait for a specified amount of time before executing a JavaScript function. The second does the same but will repeatedly execute the JavaScript function.

Note, most browsers have a minimum delay length of between 25 and 75 ms. If a shorter delay is specified, the actual delay will be the minimum delay length. Even with higher numbers, the delay is never perfect. Most web browsers will take slightly longer than the time we ask for, typically just a few milliseconds error. Some may correct their errors over time with interval timers. Also note, setting many timers with short delays on one page will cause the web browser to become slow and somewhat unresponsive. Three or four timers is usually the reliable limit.

The first method uses a window method called setTimeout() in JavaScript. The setTimeOut() method waits for a specified number of milliseconds then executes the specified code. The code can either be a direct reference to a JavaScript function, or it can be a string that will be evaluated as if it contained source code.

Syntax of JavaScript SetTimeOut() Function

window.setTimeout( referenceToYourFunction , timeInMilliseconds ); 

Example of JavaScript SetTimeOut() Method


<img id="banner">

<SCRIPT LANGUAGE="JavaScript">

<!--

var banner=0;



function changingBanner()

{

  if(banner<5){

    var img ="";

    img = "../images/banner" + banner + ".jpg";

    document.getElementById("banner").src= img;

    document.getElementById("banner").alt= 

    "JavaScript Tutorial, JavaScript SetTimeOut()";

    banner++;

    if(banner==5){

      banner=0;

    }

  }

//this JavaScript setTimeOut() function will recall the

//changingBanner() after one second

setTimeout("changingBanner()", 3000);

}



changingBanner();

-->

</SCRIPT>


Output of JavaScript SetTimeOut() Example



     Back             Next     
 

JavaScript setTimeout() Function Examples.



In order to link this page as Reference, click on below text area and pres (CTRL-C) to copy the code in clipboard or pres right click then copy the following lines after that past into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code:

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright © 2005-2006 www.globalguideline.com All rights reserved. Join Global Guide Line community. 837 visitors are online now