I am aware of the setInterval and setTimeout functions for Javascript, but
I can't seem to find an example that lets me do what I need to.
I have a script that needs to wait until a certain condition is met. In
this case, the condition is that an iframe has been reloaded completely. I
do this by examining a hidden document variable in the iframe, and when it
has changed from "" to "1" is the signal for me that the iframe is loaded.
(if there is an easier way to check this, please let me know. I am
otherwise not using frames, just one iframe).
What I need to do can be seen with this example function:
function saveFields() {
var str ;
if ( window.frames['ifrm'] ) {
while (window.frames['ifrm'].document.ifrmform.flag.value == "") {
// loop here until condition is met
}
// rest of code which should be performed AFTER condition is met
}
}
If I just let this run in my browser, the browser crashes, and I suppose
it is because all of its allotted CPU time is being used to check the
empty while loop. So I need a sleep function here, which will cause the
checking to wait, say, half a second each time. All I can see from the
setTimeout functions is that the function which calls them returns right
away, so I don't see how I can use that.
Any suggestions?
Thanks!
Steve, Denmark 4 9460
coolsti wrote: I am aware of the setInterval and setTimeout functions for Javascript, but I can't seem to find an example that lets me do what I need to.
I have a script that needs to wait until a certain condition is met. In this case, the condition is that an iframe has been reloaded completely. I do this by examining a hidden document variable in the iframe, and when it has changed from "" to "1" is the signal for me that the iframe is loaded.
(if there is an easier way to check this, please let me know. I am otherwise not using frames, just one iframe).
What I need to do can be seen with this example function:
function saveFields() { var str ; if ( window.frames['ifrm'] ) { while (window.frames['ifrm'].document.ifrmform.flag.value == "") { // loop here until condition is met } // rest of code which should be performed AFTER condition is met } }
If I just let this run in my browser, the browser crashes, and I suppose it is because all of its allotted CPU time is being used to check the empty while loop. So I need a sleep function here, which will cause the checking to wait, say, half a second each time. All I can see from the setTimeout functions is that the function which calls them returns right away, so I don't see how I can use that.
Any suggestions?
Thanks! Steve, Denmark
Look at the page source for
"http://www.geocities.com/mangokun/programming/javascript/control_setTimeout.htm"
I am not 100% sure whether this gives up the CPU while it times - but I
think it does ! Anyone who writes a timeout that doesn't isn't very clever !
coolsti said: I am aware of the setInterval and setTimeout functions for Javascript, but I can't seem to find an example that lets me do what I need to.
I have a script that needs to wait until a certain condition is met. In this case, the condition is that an iframe has been reloaded completely. I do this by examining a hidden document variable in the iframe, and when it has changed from "" to "1" is the signal for me that the iframe is loaded.
(if there is an easier way to check this, please let me know. I am otherwise not using frames, just one iframe).
What I need to do can be seen with this example function:
function saveFields() { var str ; if ( window.frames['ifrm'] ) { while (window.frames['ifrm'].document.ifrmform.flag.value == "") { // loop here until condition is met } // rest of code which should be performed AFTER condition is met } }
If I just let this run in my browser, the browser crashes, and I suppose it is because all of its allotted CPU time is being used to check the empty while loop. So I need a sleep function here, which will cause the checking to wait, say, half a second each time. All I can see from the setTimeout functions is that the function which calls them returns right away, so I don't see how I can use that.
Any suggestions?
If you want a delay, use setTimeout().
Don't try something else just because you don't know how to use setTimeout().
The following version of saveFields() will reschedule itself to execute every
half second until the flag is set:
function saveFields() {
var str ;
if ( window.frames['ifrm'] ) {
if (!window.frames['ifrm'].document.ifrmform.flag.value) {
setTimeout("saveFields()",500);
} else {
// rest of code which should be performed AFTER condition is met
}
}
}
However, rather than having this function ask "are you done yet? are you done
yet?" over and over, you might consider having the iframe's onLoad handler
trigger whatever action should be taken when it loads.
none wrote:
[...] Look at the page source for
[...]
No, don't - use Lee's setTimeout() suggestion below. The link proided
by "none" is IE only (and maybe some versions of Opera):
div1.innerHTML='<...
Referencing DOM objects doesn't work in most non-IE browsers. The
equivalent, cross-browser solution would be:
var theDiv;
if (document.getElementById) {
theDiv = document.getElementById('div1')
} else if (document.all) {
theDiv = document.all['div1']
}
theDiv.innerHTML='<...
And if you want to support Netscape 4.x, look at document.layers too. I am not 100% sure whether this gives up the CPU while it times - but I
Yes, it should because it uses setTimeout() and checks back once each
second.
--
Rob
Hi,
thanks for the various suggestions to the posters.
Actually, I solved the problem another way. I instead have the iframe
code do the work as soon as it is loaded up, so I no longer need my wait
function.
In my script which is called by the iframe:
<form name="ifrmform" method="post"
action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="savestring" value="" >
<input type="hidden" name="action" value="" >
</form>
<?php
if (trim($_POST['action']) == 'autosave')
{
// Code here to connect to database and update (save) variables
if (isset($_SESSION['timedout']))
{
// Here, if timed out, set by code that each page request sees
unset($_SESSION['timedout']);
?>
<script>
parent.timeUserOut();
</script>
<?php
}
}
?>
and in the main document script:
<script>
function timeUserOut() {
packValues(); // prepare for a timed out situation
document.form1.submit(); // auto-submit the form
}
</script>
In other words, instead of trying to check in the main document for when
the iframe is fully loaded, I use the iframe itself to initiate the
action, which of course occurs first after the iframe is fully loaded.
In this case, the iframe serves as an auto-save but my pages are also
protected by a time-out; if the user doesn't request another page
within the time out period, the user is asked to log in again at the next
page request, with all
posted variables being stored in a session variable until the user logs in
again. But with this page, the user is working via Javascript mostly
on the client side for long periods of time (hence the need for
autosave) and so the time out idea wouldn't work if the autosave went
into action. So now, when the auto-save notices a time-out, it will
call the parent JS function to pack up all the user's form variables and
force a submit to refresh the page - and since the user timed out, he/she
will be confronted with the log in page.
Too bad there isn't a simple sleep function in JS.
/Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ryan Spencer |
last post by:
Hello Everyone,
I want to have a row of periods, separated by small, say, .5 second
intervals between each other. Thus, for example, making it have the
appearance of a progress "bar".
...
|
by: Radioactive Man |
last post by:
anyone know of a function like "raw_input", which collects a string
from the user entry, but one where I can set a time limit, as follows:
time_limit = 10 # seconds
user_answer =...
|
by: Alexander Erlich |
last post by:
Hello,
I have written a function that returns a random number in dependence of the
time running on the current system. The problem is that initializing two
variables with this function _one...
|
by: Parahat Melayev |
last post by:
I am trying to writa a multi-client & multi-threaded TCP server.
There is a thread pool. Each thread in the pool will handle requests
of multiple clients.
But here I have a problem. I find a...
|
by: kiplring |
last post by:
Suppose a function which has Sleep() method in it. And I want to
recycle it. I made two buttons which call "Resume()" and "Suspend()".
But It doesn't work. The state of thread "t" will be...
|
by: Sinan Nalkaya |
last post by:
hello,
i need a function like that,
wait 5 seconds:
(during wait) do the function
but function waits for keyboard input so if you dont enter any it waits
forever.
i tried time.sleep() but when...
|
by: mark |
last post by:
Right now I have a thread that sleeps for sometime and check if an
event has happened and go back to sleep. Now instead I want the thread
to sleep until the event has occured process the event and...
|
by: Cintury |
last post by:
Hi All,
I'm developing a mobile app in VB and I was wondering if there was anyway to pause or wait a thread without putting it to sleep. I'm just trying to maintain a wireless network connection...
|
by: stayit |
last post by:
Expand the code so that the parent creates two children and then waits until both children and then waits until both children exit.
Note: The code might have something to do in UNIX.
Expand...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |