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

How to call a function in asp over a certain period of time?

Status
Not open for further replies.

UlsterVBPro

Programmer
Mar 25, 2003
4
GB
Hi!
I'm trying to implement image rotation on a .asp page.
Actually, I've already done that and every time when page refreshes, user can see a different image randomly selected, by the function written by me, from images directory.
But now client wants images to refresh the page and still images should rotate.

So, obviously, the mentioned above function is to be called after period of time of, say 20 seconds and then again and again.

That is my problem and I'd be grateful if anyone could give me an idea on how to implement this functionality.

I'm not going to use AdRotator or any other components, so
it should be just VBScript and ASP.

Thank you.
sgg
 
To sgg,

you can use meta tag of html to refresh the page after certain period of time, this you can specify using-
<META HTTP-EQUIV=&quot;REFRESH&quot; CONTENT=2>

OR

This description is given in MSDN help on dynamic HTML.
I have used this for similar page.
You can use your function as an expression here. If you want to run it at server, you can submit the page

setInterval

------------------------------------------------------------

Description

Repeatedly evaluates an expression after a specified number of milliseconds has elapsed.

Syntax
intervalID = object.setInterval(expression, msec [, language])


Parameter Description
expression : String containing the script code to execute each time the interval elapses.

msec : Integer value or numeric string specifying the length of the interval, in milliseconds.

language : Optional. String specifying the language in which the code is executed.

Return Value


Returns an integer identifier representing the interval. Use this identifier to clear (stop) the interval.

Example

The following example sets a 5-second interval. Each time the interval elapses, the background color of the document changes.

setInterval(&quot;changeColor()&quot;, 5000);
.
.
.
function changeColor()
{
if (document.body.bgColor == &quot;#ff0000&quot;) // Check if body bgColor is red by comparing to hexidecimal value
document.body.bgColor = &quot;blue&quot;;
else
document.body.bgColor = &quot;red&quot;;
}

Applies To

window

See Also
clearInterval
 
Thank you, visitorsmk, for your response.
As for refresh - it's not an option, because client doesn't want page to be reloaded.
As for setinterval - I'm going to try it today.
Thanks again.
 
You could try a javascript function that rotates a particular image after a certain period of time. This would be the same code as a rollover but instead of being governed by an onMouseover, the function would be initialized by an onLoad in the body tag. It would be like the approach described above although I wouldn't use setInterval because that is a netscape4 and above function and you can accomplish the same thing with a setTimeout call inside the function which causes it to repeat like a setInterval.
 
Thanks, guys, for your input
The only thing I forgot to mention is that these images are at the same time links to other pages.
And how would I handle this?
And one more time - the page has to be loaded and displayed for a long time, and images have to rotate without refreshing the page.
The easiest way to do rotation is to create an animated .gif out of image maps, but the problem is that after creation of animation all maps are gone.
Thanks again.
 
An animated gif wouldn't work if you want to have each image be a different link (at least not without some serious juggling). In this case, a javascript function would be the best way because when you rotate the images you also rotate the link object. Whenever I see simple things like this I like to write them up and throw them in my script library for future use. This works on my computer perfectly and does what I think you want. Of course you need to supply your own images and tailor it to your use:

[red]<html>
<head>
<script language=&quot;JavaScript&quot;>
image1 = new Image;
image1.src = &quot;image1.gif&quot;
image2 = new Image;
image2.src = &quot;image3.gif&quot;
image3 = new Image;
image3.src = &quot;image2.gif&quot;
var linkArray = new Array(&quot;var counter = 0;
function rotate()
[tab]{
[tab]counter++;
[tab]if (counter>3) counter = 1;
[tab]document.imgToRotate.src = eval(&quot;image&quot;+counter).src;
[tab]document.links[0].href = linkArray[counter - 1];
[tab]setTimeout(&quot;rotate()&quot;,2000);
[tab]}
</script>

<body onLoad=&quot;rotate();&quot;>
<a href=&quot; src=&quot;image1.gif&quot; name=&quot;imgToRotate&quot;></a>
</body>
</html>[/red]
 
NOTE: some semicolons got thrown in there at the end of the links by the TT-forum cfm code. Those aren't part of the code.
 
Will,
thanks a lot for your help - worked perfect. I didn't change a bit in your code and it worked!!!
So, thanks one more time to you and to visitorsmk.
Your responses really helped.
Good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top