MyBB Community Forums

Full Version: Random Background Images
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, i was wandering where i would put the code for random background images in Javascript.

heres my Javascript(Really i need to know what code to use to get it to do the background option in the body tag through Javascript.

Code to randomly pick the image.
<script language="JavaScript">
<!--
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array. Rememeber
// to increment the theImages[x] index!

theImages[0] = 'http://images.gamersyde.com/gallery/public/9001/1306_0011.jpg'
theImages[1] = 'http://loot-ninja.com/wp-content/uploads/2007/09/wallpaper-halo-3-01.jpg'
theImages[2] = 'http://www.xbox.com/NR/rdonlyres/0D49F9E4-B06E-4D03-8D27-0DDA3A0A61AF/0/gearsofwar2_marcus_1280.jpg'
theImages[3] = 'http://plasmasteelgames.net/images/resistance.png'

// ======================================
// do not change anything below this line
// ======================================

var j = 0
var p = theImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}

var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

//-->
</script>
You should be able to do this without JS. You can make a PHP file that generates a random image and put the URL to that where the URL for the background image goes.
ok i'll look into it thanks man