Skip to content Skip to sidebar Skip to footer

Settimeout Issue In Ie8

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, {name:'saarthak'});

Solution 1:

Probably not supported there, so have this instead:

window.setTimeout(function() {
    timeout({name:'saarthak'});
},2000);

Meaning call your function from within anonymous function.

Solution 2:

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){
          returnfunction(){
                    alert ("hello " + opts.name)            
                  }
     })({name:names[q]}), 2000);
}

see: http://jsfiddle.net/q4HYz/

Post a Comment for "Settimeout Issue In Ie8"