This script will work for 9 images named photo1.jpg through photo9.jpg, located in the same directory as the page this script is on.
Code:
<script type="text/javascript">
function random(n) {
return Math.floor((Math.random() % 1) * n);
}
document.documentElement.style.background="url('photo"+[random(9)+1]+".jpg') pink center no-repeat"
</script>
As you can see by the part after the image declaration, it will accept conventional css values for background in the usual manner. Be aware, random means random so, the same image may be used twice or more times in a row.
Bookmarks