How can I have both random background image selection and image resizing in HTML?

Ian

New member
The other day I was working in html and wanted to have the background image selected at random. I found a script on the internet and copied and pasted it:


<script language="JavaScript">
<!-- Activate cloaking device
var randnum = Math.random();
var inum = 7;
// Change this number to the number of images you are using.
var rand1 = Math.round(randnum * (inum-1)) + 1;
images = new Array
images[1] = "Tunnel.png"
images[2] = "Lincoln.png"
images[3] = "Parthenon.png"
images[4] = "Ship.png"
images[5] = "Smile.png"
images[6] = "Temple.png"
images[7] = "TylersFire.png"
// Ensure you have an array item for every image you are using.
var image = images[rand1]
// Deactivate cloaking device -->
</script>

</HEAD>

<script language="JavaScript">
<!-- Activate cloaking device
document.write('<body background="' + image + '" text="black">')
// Deactivate cloaking device -->
</script>

This code has worked fine for random selection, but I also want the picture to resize to fit the browser it's being viewed from. I tried to google it, but not of the solutions worked with the random image selector, for example, I could not find where I could put the height=100% and width=100% codes.

I want to have a randomly selected background image that resized so the background image is fully visible.
 
Back
Top