- 1). Right-click the HTML page you want to place cycling images in and select "Open With." Click your HTML editor in the list of programs to edit the JavaScript.
- 2). Add the JavaScript function to cycle the images. The following code creates an array of two images, and the "Math.random" function randomizes the image shown:
function displayHeader() {
var number = Math.floor(Math.random()*2);
var array = new Array ("images/img1.jpg", "images/img2.jpg");
document.write(array[number]);
} - 3). Link the JavaScript function to your HTML page's "onload" function. The following code is an example of linking a cycling image function:
<body onload="displayHeader()">
SHARE