This page demonstrates how to use JavaScript to generate a random background image whenever the page is loaded or refreshed. You obviously have to be careful when choosing the background images to ensure that whichever is chosen the text can still be read.

To produce this effect, in the HEAD section of the page put...

<script language="javascript">
<!-- Hide the script from old browsers
function showimage(){
//Define and populate the array
var images = new Array;
//Generate a random number then display the image from that array index
rdmImage = Math.floor(Math.random()*images.length); = 'url(' + images[rdmImage] + ')';

Change the BODY tag to read...

<body onload=showimage()>

This page created 22nd October 2004, last modified 24th October 2004

GoStats stats counter