Connecting Tech Pros Worldwide Forums | Help | Site Map

setTimeout() problem?

nobody
Guest
 
Posts: n/a
#1: Jul 20 '05
hello,

could someone explain to me why the following code stops in IE with
error whereas runs smoothly in Opera (as I expect)?

function fTurn( ) {
document.write("blabla blabla<br>");
}
function fRun() { fTurn(); setTimeout('fRun()', 2000); }
fRun();

cheers,
n.



lallous
Guest
 
Posts: n/a
#2: Jul 20 '05

re: setTimeout() problem?


Hello,

When you say: document.write('aaa') the script is deleted (also document)
but the timer is still installed (probably IE would fix this by killing your
timer too).
So you're erasing the fRun() function after the second call to fTurn().

--
Elias
"nobody" <nobody@non.existe.nt> wrote in message
news:kWBBb.207888$361.117506@news.chello.at...[color=blue]
> hello,
>
> could someone explain to me why the following code stops in IE with
> error whereas runs smoothly in Opera (as I expect)?
>
> function fTurn( ) {
> document.write("blabla blabla<br>");
> }
> function fRun() { fTurn(); setTimeout('fRun()', 2000); }
> fRun();
>
> cheers,
> n.[/color]


nobody
Guest
 
Posts: n/a
#3: Jul 20 '05

re: setTimeout() problem?


hello,
[color=blue]
> When you say: document.write('aaa') the script is deleted (also document)
> but the timer is still installed (probably IE would fix this by killing your
> timer too).
> So you're erasing the fRun() function after the second call to fTurn().[/color]

thanks Elias. do you have any idea why this works in Opera without
error? is there is any solution of using a construction of that kind in
IE without erasing a called function?

cheers,
n.
lallous
Guest
 
Posts: n/a
#4: Jul 20 '05

re: setTimeout() problem?


Try not to use document.write() to change the document's content, learn
DHTML and use the DOM (Document Object Model) to manipulate the page
dynamically.

--
Elias
"nobody" <nobody@non.existe.nt> wrote in message
news:yHCBb.208137$361.61829@news.chello.at...[color=blue]
> hello,
>[color=green]
> > When you say: document.write('aaa') the script is deleted (also[/color][/color]
document)[color=blue][color=green]
> > but the timer is still installed (probably IE would fix this by killing[/color][/color]
your[color=blue][color=green]
> > timer too).
> > So you're erasing the fRun() function after the second call to fTurn().[/color]
>
> thanks Elias. do you have any idea why this works in Opera without
> error? is there is any solution of using a construction of that kind in
> IE without erasing a called function?
>
> cheers,
> n.[/color]


Closed Thread


Similar JavaScript / Ajax / DHTML bytes