Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Need random image loader

  1. #1
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need random image loader

    Hi, I know I have seen this script somewhere here before, but I can't find it. The script I need is a script that randomly selects an image from a certain folder and diplays it. Each time you refresh, a different picture is displayed, but until you refresh it stays the same. Thanks for any help.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Was it a client side script (javascript) or server-side (PHP,ASP,etc.) I could probably write something up in PHP, but it may take a little while (about 20 or so minutes to write, and test).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I don't know what it was, whichever works best. It was something you added into the .html file, so it is probably client side.

  4. #4
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have found a website with something similar to what I want. The website www.railcarphotos.com has a random feature that will show you ten random train car photos, and each time you refresh, the ones displayed change. http://www.railcarphotos.com/Search....&Search=Search

    The only thing is, all I want to use this for is to have my websites banner change every time that someone visits the page.

    I think what the person who asked the first time I saw this a while back was trying to do was to randomly generate adds, so that a different ad was displayed each time, so the ad wasn't the same every time.

  5. #5
    Join Date
    Nov 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Found a better example, http://www.pwrs.ca/ The main image changes on refresh.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      <script type="text/javascript">
        window.onload = function() {
          var randomImages = [
            "folder1/image1.png",
            "folder2/image2.jpg",
            "folder2/image3.gif",
            "folder3/image4.tga"
          ];
          document.images['random_image'].src = randomImages[Math.floor(Math.random() * randomImages.length)];
        };
      </script>
    </head>
    <body>
      <img id="random_image" src="defaultImage.png">
    I had to answer this purely because it's 0547, my vision's getting a little blurry, and I read the "random" in the title as "condom."
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,069
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey View Post
    I had to answer this purely because it's 0547, my vision's getting a little blurry, and I read the "random" in the title as "condom."
    You need more than rest then.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You're not wrong.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by Twey View Post
    I read the "random" in the title as "condom."
    Wow, that's just...wow. My opinion is you need sleep.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Twelve hours later, still no sleep.

    Oh well, maybe soon.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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