image java script question

  • Started
  • Last post
  • 2 Responses
  • traut

    i know its out there but i can not for the life of me find it. im looking to find a java script that will randomly load an image from a group or folder of images each time a website is loaded / refreshed.

  • dibec0

    <!-- TWO STEPS TO INSTALL RANDOM IMAGE:

    1. Copy the coding into the HEAD of your HTML document
    2. Add the last code into the BODY of your HTML document -->

    <!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

    <HEAD>

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    // Set up the image files to be used.
    var theImages = new Array() // do not change this
    // To add more image files, continue with the
    // pattern below, adding to the array.

    theImages[0] = '1.gif'
    theImages[1] = '2.gif'
    theImages[2] = '3.gif'
    theImages[3] = '4.gif'

    // do not edit anything below this line

    var j = 0
    var p = theImages.length;
    var preBuffer = new Array()
    for (i = 0; i < p; i++){
    preBuffer[i] = new Image()
    preBuffer[i].src = theImages[i]
    }
    var whichImage = Math.round(Math.random()*(p-1));
    function showImage(){
    document.write('<img src="'+theImages[whichImage]+'">');
    }

    // End -->
    </script>

    </HEAD>

    <!-- STEP TWO: Copy this code into the BODY of your HTML document -->

    <BODY>

    <SCRIPT LANGUAGE="JavaScript">

    <!-- Begin
    showImage();
    // End -->
    </script>

  • traut0

    thx dibec