Código:
<!doctype html> <html lang="es"> <head> <meta charset="UTF-8"> <title>Cambiar fondo de p�gina con javascript • by Alfredo Gonz�lez P.</title> <script type="text/javascript"> fondos = new Array(); fondos[0] = "images/1.jpg"; fondos[1] = "images/2.jpg"; fondos[2] = "images/3.jpg"; fondos[3] = "images/4.jpg"; fondos[4] = "images/5.jpg"; fondos[5] = "images/6.jpg"; fondos[6] = "images/7.jpg"; fondos[7] = "images/8.jpg"; fondos[8] = "images/9.jpg"; fondos[9] = "images/10.jpg"; fondos[10] = "images/11.jpg"; fondos[11] = "images/12.jpg"; fondos[12] = "images/13.jpg"; fondos[13] = "images/14.jpg"; fondos[14] = "images/15.jpg"; // tambi�n se puede crear un array as� // var fondos = ["images/fondo.png","images/fondo1.png","images/fondo2.png"] function fondoBody() { var image = fondos[Math.floor(Math.random()*fondos.length)] document.body.style.backgroundImage ="url("+image+")"; } </script> </head> <body onLoad="javascript:fondoBody();"> </body> </html>