SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Aug 30, 2003, 01:57 #1
- Join Date
- May 2003
- Location
- Fontana, Ca
- Posts
- 23
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Loading Different Images each Visit
I would like to display a different set of images each time a person visits a web site. I have seen this done in many banner advertisments and product photos. Can someone tell me how this can be done with Javascript?
Thanks.
-
Aug 30, 2003, 07:29 #2
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi Xavier,
if you mean each individual sees a different image on each visit, you need to use a cookie or dbms to store a record of images already seen.
if you mean a different image each time the page is visited, you simply need to use a randomizer.
1) place your images in an array
2) create a random number
3) use that number to access the image
4) display the image
something like:
Code:var myPics = new Array(); myPics[0] = 'pic1.gif'; myPics[1] = 'pic2.gif';myPics[2] = 'somepic.gif';myPics[3] = 'anotherpic.jpg'; var maxNum = myPics.length; var randNum = Math.floor( Math.random() * maxNum); var imgSrc = myPics[randNum]; <img src = imgSrc.....
Where the World Once Stood
the blades of grass
cut me still
-
Aug 30, 2003, 17:38 #3
- Join Date
- Oct 2000
- Posts
- 304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There are quite a few scripts around for this.
Here is one that's easy to implement:
http://jscode.com/js_random_image.shtml
Bookmarks