Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

whats the javascript code for...?

changing an image each time a page reloads...?

4 Answers

Relevance
  • MrOrph
    Lv 6
    1 decade ago
    Favorite Answer

    <!-- 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">

    <!-- This script and many more are available free online at -->

    <!-- The JavaScript Source!! http://javascript.internet.com/ -->

    <!-- 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">

    <!-- This script and many more are available free online at -->

    <!-- The JavaScript Source!! http://javascript.internet.com/ -->

    <!-- Begin

    showImage();

    // End -->

    </script>

    <p><center>

    <font face="arial, helvetica" size"-2">Free JavaScripts provided<br>

    by <a href="http://javascriptsource.com">the/ JavaScript Source</a></font>

    </center><p>

    <!-- Script Size: 1.49 KB -->

  • 1 decade ago

    Javascript is a means to provide an interactive web application. Simple examples are replacing images. More complex ones are changing the entire layout of the application. Move things around. Send and receive information in the background to and from the server as well as provide interactive feed back to the end-users. If you want to see what javascript can do when used to the max check out www.meebo.com their entire service is created using javascript and a technology known as AJAX

  • 1 decade ago

    You could do this:

    <script Language="JavaScript">

    tips = new Array(Y)

    tips[0] = "<img src=..X>"

    tips[1] = "<img src=..X>"

    tips[2] = "<img src=..X>"

    index = Math.floor(Math.random() * tips.length)

    document.write("<center>" + tips[index] + "</center><p>")

    </script>

    Where X defnes the different images (changing each time) you can add more by simply adding another line

    E.G: in this case the next image would be:

    tips[3] = "<img src=..X>"

    in the same way as you can remove them by simply deleting the unrequired text.

    But remember the Y command must define how many you have, in this caase 3.

    Hope his helps :D

  • 1 decade ago

    That function is called a Random Image function. Below is a link to a site which has the code -it needs to be pasted into your HTML page and customized for the pics you are using for the function.

Still have questions? Get your answers by asking now.