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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I pause this function?

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
0
0
US
I'm trying to get a short (5 second) pause in the following function and can't seem to get it to work. I've been trying to maybe use setTimeout but, can't get it to work.

Code:
<script type="text/javascript">
function newBrowser()
{
var i=1;
for (i=1;i<=varNUM;i++)
{
window.open(varURL);
}
}
</script>

[!]The AutoSavers![/!] [2thumbsup]
 
So are you saying I should create a second function for the delay and then just call that function in the middle of my existing one or just use the setTimeout command in my existing function like below? This example doesn't work and just ignores the setTimeout.

Code:
<script type="text/javascript">
function newBrowser()
{
var i=1;
for (i=1;i<=varNUM;i++)
{
car cmd = window.open(varURL);
setTimeout(cmd, 5000);
}
}
</script>

[!]The AutoSavers![/!] [2thumbsup]
 
There are only four lines in the link. I am sure you can read it again and again many times including the commas and apostrophes before you finish your lunch.
 
The trouble I'm having is getting the delay in the middle of my for loop. If I take the code from that page verbatim and call that function after the window.open line it seems to be running the window.open command 5 times and then it runs the alert 5 times rather than running the window.open + alert 5 times together.

Code:
<script type="text/javascript">
function strBrowser()
{
var i=1;
for (i=1;i<=varNUM;i++)
{
var cmd = window.open(varURL)
delay(5000);
}
}
</script>

[!]The AutoSavers![/!] [2thumbsup]
 
First thing first, why you take that mile to set i=1 and don't care to define what varNum is? and then varURL?
 
cbsarge - did you notice the link to the pause() method on the link Dian provided?
 
Yes - I looked at that and have tried using that information in my script unsuccessfully. I was already aware of the setTimeout command and have tried to just copy and paste the function from the referenced webpage delay() into my page and then call that function from within my loop but, it doesn't seem to be working.

[!]The AutoSavers![/!] [2thumbsup]
 
I detect some lack of spirited approach to programming. That does not help a career.
[tt]
function strBrowser()
{
var i=1;
for (i=1;i<=varNUM;i++)
{
var cmd = 'window.open("'+varURL+'")';
setTimeout(cmd, (i-1)*5000);
}
}
[/tt]
This time you need to read every comma and apostroph of what I posted rather than that in the link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top