www.webdeveloper.com
Results 1 to 3 of 3

Thread: Loading a background image from array

  1. #1
    Join Date
    Nov 2010
    Posts
    11

    Loading a background image from array

    Hi everyone,

    I have coded in html/php/css, but have not done anything too elaborate. I was looking at a site that had a different image every time on reload. When looking at the source code for the site, I found the following code that was placing the background.

    <style type="text/css">
    body {
    background-image: url(assets/bg002.jpg);
    }
    </style>

    On every reload the "bg002.jpg" portion of the code would change. Can anyone explain a method or script that could be causing this? There is no other code on the page that would refer to an array that the background images are being caller from.

    Many thanks in advance!!

  2. #2
    Join Date
    Jul 2009
    Location
    Tennessee
    Posts
    28
    If there's no hint of anything in the page source, they're using a scripting language like PHP to randomly select the image filename before the page is rendered in your web browser.

    It's the same as doing the following:

    Code:
    <?php
        $myVar = "Hello";
        echo $myVar;
    ?>
    When this script is executed and rendered in the browser, you would see only the text "Hello".

    Similarly, the "bg002.jpg" portion of the page source you're looking at is being printed using some random value. You just can't see the code used to choose the image filename because that processing is done on the server side (before your browser receives a response from the web server); you just see the output of some echo statement.

  3. #3
    Join Date
    Nov 2010
    Posts
    11
    Hi Dave,

    That helped clear it up! I thought this might be one way to achieve this and just wanted to get an affirmation.

    Thanks for all your help. This should help get me started!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles