Forum Moderators: open

Message Too Old, No Replies

Need this script to be random

         

lindaw65

7:54 pm on Apr 3, 2009 (gmt 0)

10+ Year Member



This is exactly what we needed to show banners of different sizes with different URLs. The problem is the images are not random. Is there any way to make this work showing the images as random instead of #1 always being #1 when they hit refresh or return back to this page?

Thanks!

var ImageLoad =
[
['index.htm', 'graphics/three.jpg', 'Raindrops on a Leaf'],// ['URL to linked page', 'URL to image', '']//
['index.htm', 'graphics/four.jpg', 'Jungle Dream'],// Add as many images as you like seperated by commmas//
['index.htm', 'graphics/five.jpg', 'Daisies'],// Almost ALL errors are caused by the url or path being wrong //
['index.htm', 'graphics/six.jpg', 'Sunflowers']// The LAST image declaration does NOT have a comma after it//
];

var ImageCount= 2;// ***** Change this to the total number of images loaded above ***** //
var ImageDelay= 5000;// ***** Set this to the delay interval desired. 5000 = 5 seconds.//
var LinkTarget= "_self"// ***** Defines where you want linked page to open. _self, _blank, _top, etc//
var ImageIndex= 0;// DO NOT ALTER//
var FirstLoad = 0;// DO NOT ALTER//
var QuickStartID = 0; // DO NOT ALTER//
var htmlString = ""// DO NOT ALTER //

// This function rotates the banner //
function ImageChange()

{

htmlString = '<center>';
htmlString = htmlString + '<font face = "Verdana" size="3">';// Font and Font Size for caption may be changed here//
htmlString = htmlString + '<font color = "#FFFFFF">';
htmlString = htmlString +'<a target="';
htmlString = htmlString + LinkTarget;
htmlString = htmlString + '" href="';
htmlString = htmlString + ImageLoad[ImageIndex][0];
htmlString = htmlString + '"><img border="0" src="';// Image border size may be changed here//
htmlString = htmlString + ImageLoad[ImageIndex][1];
htmlString = htmlString + '"></a><br>';
htmlString = htmlString + ImageLoad[ImageIndex][2];
htmlString = htmlString + '</font>';
htmlString = htmlString + '</center>';

document.getElementById('MagicImage').innerHTML = htmlString;

if(ImageIndex == ImageCount - 1)// This statement increments image displayed and resets if displaying last image //
{
ImageIndex= 0;
}
else
{
ImageIndex++;
}

if(FirstLoad == 0)// Determins if this is the first time function has run. //
{
SlowFinish();
}

}
// End Funtion //

// This function ensures first banner is displayted without a delay //
function QuickStart()
{
QuickStartID=setInterval("ImageChange()", 1000);
}
// End Funtion //

// This function sets display rate to user defined speed //
function SlowFinish()
{
clearInterval(QuickStartID);
FirstLoad = 1;
setInterval("ImageChange()", ImageDelay);
}
// End Funtion //

QuickStart()

whoisgregg

6:02 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of incrementing ImageIndex, you can generate it randomly with something like this:

ImageIndex = Math.floor( Math.random() * ImageLoad.length );