Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is a non blocking loop possible?

Status
Not open for further replies.

riffraff76

Technical User
Jul 2, 2008
7
GB
Hi all,

I wonder is it possible to have the following:
I have a page where the user can click a button and an iframe URL is loaded.
I wish to have another button where it will start a loop that will continuously reload the iframe (as if the user was continuously pressing the original button) until the user presses a third 'stop' button.

So far i can only have the loop begin but then the UI is inaccessible so there is no way i can press the button which stops the loop. This is probably as the UI is in the same thread as the javascript. (i'm using firefox 3).

Can this be done in any way?
So far i have to rely on a macro addon to do this but i have to rely on simply a timer to determine when the next reload occurs but i'd really rather use a flag/event in the javascript to signal when to go to the next iteration.

Thanks in advance!
 
Investigate "setInterval" or "setTimeout" to perform your loops, and "clearInterval" or "clearTimeout" respectively to stop the loops.

If you use a standard for or while loop, then JS will probably freeze the browser.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for that, i've had a look into some these before posting but i still can't figure out how to implement a loop from them in a way that will solve this. I can't 'spawn' a loop using e.g. setTimeout, the only thing i can do with this is to run a function in the future so to speak, the looping element is still going to block the GUI.

I even tried doing it by implementing a little function that checks for the existence of an image file. The idea being i could stop the loop by deleting the file. This was looking good until i ran into a really weird problem were the loop continues, i then delete the file, the loop stops...i get all excited that i've cracked it.... but from then on when i put the image file back and start the loop again the script cant seem to see it again??!

boy o boy...javascript in browsers has got soooo many nuances, seems i lick one problem and run into another!
I think i'm going to fall back on .NET to get what i need with threading.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top