473,385 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

setTimout problem

Hello,

I have a for loop, which calls a method

for (var i = 0; i < GmailXChat.gmailChatFrames.length; i ++)
{
// myObjectArray[i].constructIframe();
}

the method 'constructIframe();' invloves constructing an HTML iframe,
adding various elements to it and displaying it on a page. When
constructing an iframe and adding it to a page dynamically, it is
necessary to use setTimeout('finishIframe()',0) to complete the
iframe. Where 'finishIframe()' adds any content to the iframe
itself. This must be done since it stops the browser from attempting
to add content to the iframe before any of the elements to be added
have been created.

This all works fine if the loop on cycles only once. However if the
loop cycles more than once the following problem occurs:

Where the call 'setTimeout('finishIframe()',0)' occurs, control is
returned (to the loop), so the loop cycles round and calls
myObjectArray[i].constructIframe() again, before the original call to
myObjectArray[i].constructIframe() is actually completed.

I need a call to myObjectArray[i].constructIframe() to complete fully
(including the call to setTimeout('finishIframe()',0)), before control
is returned to the loop, and the loop cycles.

Hope someone can help, have been stuck on this for quite a while.

Many thanks,

Jack

Jul 5 '07 #1
3 1345
On Jul 5, 10:50 am, "jackwoot...@gmail.com" <jackwoot...@gmail.com>
wrote:
Hello,

I have a for loop, which calls a method

for (var i = 0; i < GmailXChat.gmailChatFrames.length; i ++)
{
// myObjectArray[i].constructIframe();

}

the method 'constructIframe();' invloves constructing an HTML iframe,
adding various elements to it and displaying it on a page. When
constructing an iframe and adding it to a page dynamically, it is
necessary to use setTimeout('finishIframe()',0) to complete the
iframe. Where 'finishIframe()' adds any content to the iframe
itself. This must be done since it stops the browser from attempting
to add content to the iframe before any of the elements to be added
have been created.

This all works fine if the loop on cycles only once. However if the
loop cycles more than once the following problem occurs:

Where the call 'setTimeout('finishIframe()',0)' occurs, control is
returned (to the loop), so the loop cycles round and calls
myObjectArray[i].constructIframe() again, before the original call to
myObjectArray[i].constructIframe() is actually completed.

I need a call to myObjectArray[i].constructIframe() to complete fully
(including the call to setTimeout('finishIframe()',0)), before control
is returned to the loop, and the loop cycles.

Hope someone can help, have been stuck on this for quite a while.

Many thanks,

Jack
To add some more information, to me it is like JavaScript becomes
multi threaded. Where a separate thread is started the moment the
call setTimeout('finishIframe()',0) is made, and therefore the
original thread returns to the loop. I know JavaScript is not multi
threaded though.

Jul 5 '07 #2
On Jul 5, 6:53 am, "jackwoot...@gmail.com" <jackwoot...@gmail.com>
wrote:
On Jul 5, 10:50 am, "jackwoot...@gmail.com" <jackwoot...@gmail.com>
wrote:
Hello,
I have a for loop, which calls a method
for (var i = 0; i < GmailXChat.gmailChatFrames.length; i ++)
{
// myObjectArray[i].constructIframe();
}
the method 'constructIframe();' invloves constructing an HTML iframe,
adding various elements to it and displaying it on a page. When
constructing an iframe and adding it to a page dynamically, it is
necessary to use setTimeout('finishIframe()',0) to complete the
iframe. Where 'finishIframe()' adds any content to the iframe
itself. This must be done since it stops the browser from attempting
to add content to the iframe before any of the elements to be added
have been created.
This all works fine if the loop on cycles only once. However if the
loop cycles more than once the following problem occurs:
Where the call 'setTimeout('finishIframe()',0)' occurs, control is
returned (to the loop), so the loop cycles round and calls
myObjectArray[i].constructIframe() again, before the original call to
myObjectArray[i].constructIframe() is actually completed.
I need a call to myObjectArray[i].constructIframe() to complete fully
(including the call to setTimeout('finishIframe()',0)), before control
is returned to the loop, and the loop cycles.
Hope someone can help, have been stuck on this for quite a while.
Many thanks,
Jack

To add some more information, to me it is like JavaScript becomes
multi threaded. Where a separate thread is started the moment the
call setTimeout('finishIframe()',0) is made, and therefore the
original thread returns to the loop. I know JavaScript is not multi
threaded though.
The concept is the same though, when you a setTimeout() it does an
asynchronous function call to finishIframe, then executes the next
line of code
In other words, your JS makes a call to finishIframe then executes the
next line. The function finishIframe can do what ever work it needs to
do, but your main JS code is also being executed at the same time

Jul 5 '07 #3
On Jul 6, 5:04 am, dave <dave.wa...@gmail.comwrote:
On Jul 5, 6:53 am, "jackwoot...@gmail.com" <jackwoot...@gmail.com>
wrote:
On Jul 5, 10:50 am, "jackwoot...@gmail.com" <jackwoot...@gmail.com>
wrote:
Hello,
I have a for loop, which calls a method
for (var i = 0; i < GmailXChat.gmailChatFrames.length; i ++)
{
// myObjectArray[i].constructIframe();
}
the method 'constructIframe();' invloves constructing an HTML iframe,
adding various elements to it and displaying it on a page. When
constructing an iframe and adding it to a page dynamically, it is
necessary to use setTimeout('finishIframe()',0) to complete the
iframe. Where 'finishIframe()' adds any content to the iframe
itself. This must be done since it stops the browser from attempting
to add content to the iframe before any of the elements to be added
have been created.
This all works fine if the loop on cycles only once. However if the
loop cycles more than once the following problem occurs:
Where the call 'setTimeout('finishIframe()',0)' occurs, control is
returned (to the loop), so the loop cycles round and calls
myObjectArray[i].constructIframe() again, before the original call to
myObjectArray[i].constructIframe() is actually completed.
I need a call to myObjectArray[i].constructIframe() to complete fully
(including the call to setTimeout('finishIframe()',0)), before control
is returned to the loop, and the loop cycles.
Hope someone can help, have been stuck on this for quite a while.
Many thanks,
Jack
To add some more information, to me it is like JavaScript becomes
multi threaded. Where a separate thread is started the moment the
call setTimeout('finishIframe()',0) is made, and therefore the
original thread returns to the loop. I know JavaScript is not multi
threaded though.
Control never leaves the loop in the first place. The call to
setTimeout establishes a function that will run later. As soon at
that call returns, the loop continues. Whatever was assigned to
setTimeout doesn't run until after the main funciton is complete.

The concept is the same though, when you a setTimeout() it does an
asynchronous function call to finishIframe, then executes the next
line of code
No, it makes a call to window.setTimout which will wait for the end of
the function, then wait for the timeout period, then execute whatever
function it was passed - it is all completely synchronous.

In other words, your JS makes a call to finishIframe then executes the
next line. The function finishIframe can do what ever work it needs to
do, but your main JS code is also being executed at the same time
The call to setTimeout establishes a function that will run completely
asynchronously.

<URL: http://developer.mozilla.org/en/docs...dow.setTimeout >
--
Rob

Jul 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
1
by: anagai | last post by:
hi I would like to cancel a settimout from happening. I dont want it to execute the expression at all. clearTimeout just cancels the delay but executes the expression anyway. I want to cancel...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
4
by: Roger Withnell | last post by:
Within a function I would like to use a variable in the setTimout string, for example: var jHello = 'Hello'; setTimeout("alert(" + jHello + ")", 1000); This gives jHello undefined error. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.