setTimeout() in IE

  • Thread starter Chris Moltisanti
  • Start date
C

Chris Moltisanti

Hey,

I am using the setTimeout() function in IE to pause the execution of
another funciton for a few seconds. My function is as follows:

funtion test(e) {
// the parameter 'e' is the event
// do something
}

in order to execute test(e) correctly I need to pass the 'e' event
parameter down in the setTimeout() function. However, from what I have
read IE (unlike Mozilla) doesn't allow you to pass parameters in
setTimeout(), unless those parameters are strings.
Therefore when I call setTimeout(test, 1000);
I am unable to use the param 'e' in my test() function.
Does anybody know of a way around this?

I'd appreciate any help. I've spent ages on this......it works in
Firefox but not IE.

Cheers,

Chris
 
J

JimK

Hey,

I am using the setTimeout() function in IE to pause the execution of
another funciton for a few seconds. My function is as follows:

funtion test(e) {
// the parameter 'e' is the event
// do something
}

in order to execute test(e) correctly I need to pass the 'e' event
parameter down in the setTimeout() function. However, from what I have
read IE (unlike Mozilla) doesn't allow you to pass parameters in
setTimeout(), unless those parameters are strings.
Therefore when I call setTimeout(test, 1000);
I am unable to use the param 'e' in my test() function.
Does anybody know of a way around this?

I'd appreciate any help. I've spent ages on this......it works in
Firefox but not IE.

Cheers,

Chris

Works in IE for me

function test1(e)
{
setTimeout("eval(e)", 10000);
}

function test2()
{
alert ('This is a Javascript Alert')
}


<A HREF="#" onClick="e = 'test2()', test1(e)">alert</A>
 
C

Csaba Gabor

Chris said:
I am using the setTimeout() function in IE to pause the execution of
another funciton for a few seconds. My function is as follows:

funtion test(e) {
// the parameter 'e' is the event
// do something
}

in order to execute test(e) correctly I need to pass the 'e' event
parameter down in the setTimeout() function. However, from what I have
read IE (unlike Mozilla) doesn't allow you to pass parameters in
setTimeout(), unless those parameters are strings.
....
Both allow you to pass parameters directly (without eval):

function test(e) {
window.setTimeout(function(evt, myVar) {return function() {
alert (myVar + " got the event " + evt.type);
} } (e, "Fred"), 1000);
}

For further reading see:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/94165d8695faf91d/

Csaba Gabor from Vienna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top