Reputation: 34006
I have the following javascript in MSIE:
setTimeout(myFunction, 1000, param );
this seems to work in all browsers except internet explorer. the param just doesnt get forwarded to the function. looking at the debugger, it is undefined.
Upvotes: 23
Views: 37926
Reputation: 348992
param
in Internet explorer specifies whether the code in myFunction
is JScript, JavaScript or VBscript See also: MSDN. It does not behave like other browsers.
The following will work:
setTimeout(function() {
myFunction(param);
}, 1000);
The previous line does not exactly mimic setTimeout
in Firefox etc. To pass a variable, unaffected by a later update to the param
variable, use:
setTimeout( (function(param) {
return function() {
myFunction(param);
};
})(param) , 1000);
Upvotes: 42
Reputation: 325
Take a look at http://www.makemineatriple.com/2007/10/passing-parameters-to-a-function-called-with-settimeout
Looks like you'll need something like this:
setTimeout(function(){ myFunction(param) }, 1000);
Upvotes: 3
Reputation: 8333
you can use closure:
setTimeout(function(){myFunction(param)}, 1000);
Upvotes: 1
Reputation: 4291
How about this:
setTimeout(function(){
myFunction(param);
}, 1000);
Upvotes: 1
Reputation: 114367
Use an anonymous function:
setTimeout(function() { myFunction(param) }, 1000);
Upvotes: 1
Reputation: 298166
That isn't a parameter. Apparently, that last argument is denoting the scripting language.
Use an anonymous function instead:
setTimeout(function() {
myFunction(param);
}, 1000);
Upvotes: 1
Reputation: 219938
Internet Explorer does not allow you to pass parameters like that. You'll have to do it explicitly from the callback function:
setTimeout(function(){
myFunction(param);
}, 1000);
Quote from MDN:
Note that passing additional parameters to the function in the first syntax does not work in Internet Explorer.
Upvotes: 4