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

How to make GIF image change on refresh

Status
Not open for further replies.

jpal

MIS
Jul 12, 2004
1
US
I know this is probably not complicated but I can't figure it out. Can someone point me to how you make a different image appear (replacing the original) on a page with each time the page is refreshed?
 
That depends on what you're doing.

If you're refreshing something like an asp or php page, you would have some sort of server-side script that works out what the most current picture is and insert the file name into the <img src="" /> tag during the refresh.

A simple alternative to this (especially if the image is something like a whatever-cam photo) is to just have whatever is producing the images overwrite the previous image as it updates. This way, every time the web page refreshes, it gets the most current image.

SELECT user
FROM users
WHERE common_sense IS EQUAL TO NULL;

-Shrubble
 
Yet another option is to do it client side with Javascript.
Set up an array with the names of possible images, then write out the HTML with the appropriate filename in.
That is assuming the client has JavaScript enabled in their browser.
If you choose this method there are plenty of ready made scripts out there. Try for starters.

 
If you're just interested in selecting a semi-random picture from an array of pictures, you can go off this:

Code:
var now = new Date();
var ms = now.getMilliseconds();

var picArray = new Array(25); //fill this with your pix

var randomIndex = ms % picArray.length; //mod arithmetic

Then, set SRC of the IMG of your choice to picArray[randomIndex].

It's not "strictly" random, but it should ensure a better a reasonable probability of not getting the same image twice in a row.

'not sure if that's what you wanted.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top