Digital Point Forums
Winn and Sims

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Aug 13th 2005, 1:17 pm
sarahk's Avatar
sarahk sarahk is offline
iTamer
 
Join Date: Mar 2004
Location: itamer @ Fibs
Posts: 9,583
sarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond repute
Phone Verified
Can I have multiple window.setTimeout calls?

I'm just updating ad scripts on a client site and they've got multiple window.setTimeout's being set as different ads rotate.

To start with they were using the same function names and that was causing problems.

But even with everything fixed only one will rotate which leads me to suspect that window.setTimeout can only be used once!

Can anyone verify that?

Places I've been hunting:
Reply With Quote
  #2  
Old Aug 13th 2005, 3:42 pm
Kings Kings is offline
Grunt
 
Join Date: Jul 2004
Posts: 37
Kings is on a distinguished road
I think you overwrite it, each time you use it. Just like window.load. You need to use a wrapper function to set it, just like addLoadEvent.
Reply With Quote
  #3  
Old Aug 13th 2005, 6:03 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
You can use setInterval instead. If you have to use setTimeout, use something like this:

javascript Code:
function to()
{
        for(var i = 0; i < f.length; i++)
                (f[i])(i);
        window.setTimeout(to, 1000);
}

var f = new Array(0);
f.push(alert);
f.push(alert);
f.push(alert);
window.setTimeout(to, 1000);

J.D.

Last edited by digitalpoint; Sep 4th 2005 at 7:14 pm. Reason: Added JavaScript BBCode
Reply With Quote
  #4  
Old Aug 13th 2005, 7:14 pm
TommyD's Avatar
TommyD TommyD is offline
of the Nightfall
 
Join Date: Apr 2005
Posts: 1,397
TommyD has a spectacular aura aboutTommyD has a spectacular aura about
I thought you could assign timeouts to variables, and have more than one.

Might want to test if you are interested.

hth,

tom
Reply With Quote
  #5  
Old Aug 13th 2005, 10:38 pm
sarahk's Avatar
sarahk sarahk is offline
iTamer
 
Join Date: Mar 2004
Location: itamer @ Fibs
Posts: 9,583
sarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond reputesarahk has a reputation beyond repute
Phone Verified
Hmm, thanks for the replies

went to test it out using the devguru script with changes
html4strict Code:
<html>
<head>
<script type="text/javascript">
function displayAlert1()
{
alert("The GURU sez hi!")
window.setTimeout("displayAlert1()",5000);
}
function displayAlert2()
{
alert("alternate message")
window.setTimeout("displayAlert2()",6000);
}
</script>
</head>
<body>
<form>
Click on the button.
<br>
After 5 seconds, an alert will appear.
<br>
<input type="button" onclick="setTimeout('displayAlert1()',5000)" value="Click Me">
<br>
<input type="button" onclick="setTimeout('displayAlert2()',6000)" value="Click Me">
</form>
</body>
</html>
and it seems ok, so back to the drawing board on problem identification!

Last edited by digitalpoint; Sep 4th 2005 at 7:15 pm. Reason: Added HTML BBCode
Reply With Quote
  #6  
Old Aug 13th 2005, 11:56 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
How setTimeout is scheduled is browser-specific. For example, if you try this code in FF, it will bring up two alerts immediately, but then will pop a new one only after you dismiss some or all of the existing alerts. IE will create just one at a time.

javascript Code:
<script type="text/javascript">
window.setTimeout("alert(0)", 1000);
window.setTimeout("alert(1)", 1000);
window.setTimeout("alert(2)", 1000);
window.setTimeout("alert(3)", 1000);
</script>

Don't dismiss the alerts, but instead just move them to see what I mean. It appears that setInterval works the same way.

J.D.

Last edited by digitalpoint; Sep 4th 2005 at 7:15 pm.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating Phone Calls mr_tim General Marketing 10 Mar 10th 2006 7:59 pm
Accessing a element of parent window in child window livehed Programming 0 Jun 28th 2005 7:49 am
setTimeout() problem st3v1nsk1 JavaScript 1 Apr 21st 2005 1:03 pm
Sales calls.... ROAR General Chat 7 Feb 11th 2005 9:53 am
Multiple Browsers Window Injection Vulnerability mushroom General Chat 3 Dec 9th 2004 11:09 am


All times are GMT -8. The time now is 6:28 pm.