Webwork
/
Random Image with Link and Caption

This JavaScript randomizes the image along with its caption and URL. It will work with as few as two image and as many as you feel like adding.

It is a very useful way to keep a Web site home page looking fresh for return visitors.

Web page:
Source:
<script language="JavaScript">

images = new Array(5);

images[0] = "<a style='font: bold 10px/28px verdana, sans-serif; color: #666; letter-spacing: 3px; text-decoration: none; ' href = 'http://www.re-vision.com/photography/rome2006/index.html'><img src='images/0.jpg' alt='Photographs of Rome and Florence' border='0'><br />Photographs of Rome and Florence »</a>";

images[1] = "<a style='font: bold 10px/28px verdana, sans-serif; color: #666; letter-spacing: 3px; text-decoration: none; ' href = 'http://www.re-vision.com/photography/barcelona/barcelona-cover.html'><img src='images/1.jpg' alt='Photographs of Barcelona, Catalonia' border='0'><br />Photographs of Barcelona, Catalonia »</a>";

images[2] = "<a style='font: bold 10px/28px verdana, sans-serif; color: #666; letter-spacing: 3px; text-decoration: none; ' href = 'http://www.re-vision.com/photography/providence1976/'><img src='images/2.jpg' alt='Photographs of Providence, Rhode Island' border='0'><br />Photographs of Providence, Rhode Island »</a>";

images[3] = "<a style='font: bold 10px/28px verdana, sans-serif; color: #666; letter-spacing: 3px; text-decoration: none; ' href = 'http://www.re-vision.com/photography/reliance/'><img src='images/3.jpg' alt='Photographs of The Reliance Building' border='0'><br />Photographs of The Reliance Building »</a>";

images[4] = "<a style='font: bold 10px/28px verdana, sans-serif; color: #666; letter-spacing: 3px; text-decoration: none; ' href = 'http://www.re-vision.com/photography/santafe/'><img src='images/4.jpg' alt='Photographs of Santa Fe, New Mexico' border='0'><br />Photographs of Santa Fe, New Mexico »</a>";

index = Math.floor(Math.random() * images.length);
document.write(images[index]);

</script>
Previous | Webwork Table of Contents | Next >