469,271 Members | 1,096 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Repeat with pause

Hi there,

First off thank you for reading.

I'm trying to get the following to work.
I want a script that does the following 9 times: jah(urlOne); and then
1 time: jah(urlTwo); then it should start at the top again.
There has to be a break in between, thats why i have the wait function
there.
Hope anybody can help me because i'm not seeing my mistake and can't
think clear any more.

Thank you for reading.

<script language="javascript" type="text/javascript">
var urlOne="messageCenter.php, msgOne";
var urlTwo="messageBanner.php, msgOne";
var waitTime="1000";

alert (urlOne);

function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
}
}
alert (urlOne + " voor de statment");
jah(urlOne);
alert (urlOne + " na de statment");
wait(waitTime);

</script>

Mar 22 '08 #1
2 1322
"ZT**********@gmail.com" <ZT**********@gmail.comwrites:
Hi there,

First off thank you for reading.

I'm trying to get the following to work.
I want a script that does the following 9 times: jah(urlOne); and then
1 time: jah(urlTwo); then it should start at the top again.
There has to be a break in between, thats why i have the wait function
there.
Hope anybody can help me because i'm not seeing my mistake and can't
think clear any more.
You've not explained what's going wrong.

Anwyay:
function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
}
}
NEVER EVER DO THAT. It will use up 100% of your CPU and probably will
block your host (browser) completely until the timeout is
finished. Possibly the host will break your script to prevent that.

Use setTimeout() instead; something like:

var count = 0;
function nineTimes() {
if (count++ < 9) {
jah(urlOne);
setTimeout(nineTimes, 1000);
}
else {
setTimeout(function() { jah(urlTwo) },1000);
}
}
nineTimes();
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Mar 22 '08 #2
Thank you all 3 of you, i'm amazed by the answer and the speed the
were provided in.
Will post my code and the site when i'm done.

Thanks again!

Gr,

Jeroen
Mar 23 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Andrew | last post: by
11 posts views Thread by Paminu | last post: by
8 posts views Thread by Wim | last post: by
2 posts views Thread by eSolTec, Inc. 501(c)(3) | last post: by
8 posts views Thread by Lloydm | last post: by
3 posts views Thread by garfunkel214 | last post: by
2 posts views Thread by bmerlover | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.