I am facing a strange issue while using javascript setTimeout function in IE8. I want to use the \'setTimeout\' function like this -
setTimeout(timeout,2000
Probably not supported there, so have this instead:
window.setTimeout(function() {
timeout({name:'saarthak'});
},2000);
Meaning call your function from within anonymous function.
If you want to call timeout with changing variable (e.g. calling timeout in loop with lot of names) you can use also in IE8:
var names = ["saarthak", "saarthak2", "saarthak3"];
for (var q in names) {
setTimeout(
(function(opts){
return function(){
alert ("hello " + opts.name)
}
})({name:names[q]}), 2000);
}
see: http://jsfiddle.net/q4HYz/