Random picture and link

Example

The above example is images of some of our different advertisers. If you refresh or reload the page in your browser, you should get a different image (if you get the same, try again.) We wrote this basic script to allow viewers of your web page to get a new look each time they come to your web page.

Source code

<script type="text/javascript">
//Javascript Created by Computerhope http://www.computerhope.com
//store the quotations in arrays
var images = [],
index = 0;

images[0] = "<a href = 'http://www.computerhope.com/index.htm'><img src='http://www.computerhope.com/banners/banner.gif' alt='Visit Computer Hope'></a>";
images[1] = "<a href = 'http://www.computerhope.com/history/index.htm'><img src='http://www.computerhope.com/banners/banner2.gif' alt='Computer History'></a>";
images[2] = "<a href = 'http://www.computerhope.com/index.htm'><img src='http://www.computerhope.com/banners/banner3.gif' alt='Visit Computer Hope'></a>";

index = Math.floor(Math.random() * images.length);
document.write(images[index]);
//done
</script>

Additional information

  • See our JavaScript definition for further information and related links on this term.