Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Rotating a photo with each reload

    I am trying to set up a web page that will load a different photo into the same space with each reload. This will show a different look each time a visitor goes to the site.
    Help! I have seen the code before, but naturally, when I need it....can't find it.

    Thanks for your help!!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    a) Best done on the server side so that users with JS disabled can enjoy that functionality.
    b) STFW (or to put it mildly GIYF)
    c) I feel altruistic today
    Code:
    ...
    <script type="text/javascript">
    photos = ['photo1.jpg','photo2.jpg','photo3.jpg'];
    function replacePhoto()
      { document.getElementById('randomImage').src = photos[Math.floor(.99*Math.random()*photos.length)];
      }
    </script>
    </head>
    <body onload="replacePhoto()">
    ...
    <img id="randomImage" alt="My image" src="photo0.jpg" />
    ...
    Last edited by Vladdy; 09-27-2005 at 05:23 AM.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •