JS sleep wait function javascript use setTimeout

Tthis code works in all previous versions of browsers

Pause code by alert

var n = 1;
alert(n);
 
n = 5;
alert(n);

Set timeout

var n = 5;
// wait 5 second / do next code
// next code put into function and call this function by setTimeout
setTimeout("nextCodeFc (n)",5000); // wait for 5000 millisecond == 5 second and execute
 
// how put string as parameter into setTimeout
var str = "Hello string parameter!";
setTimeout("nextCodeFc(\"str"\)",3000); // produce "str"
setTimeout("nextCodeFc(\""+str+"\")",3000); // produce "Hello string parameter!"
setTimeout("nextCodeFc(str)",3000); // produce Hello string parameter!
 
function nextCodeFc (n){
  // do work .........
 
  alert(n);
}
This entry was posted in Javascript css html and tagged , . Bookmark the permalink.


Comments are closed.

572 views