Funzione back() funzionante: controlla rispetto alla tua e nota le differenze.
Indizi:
- gli array, in javascript, iniziano dall'indize 0 (zero)
- non esiste elemento.style.backgroundImage, ma solamente elemento.style.background, che va 'riempito' con tutti gli attributi, in particolare anche il no-repeat, oltre all'url dell'immagine.
- non chiamare una variabile con lo stesso nome di un tag! si sa mai che i browsers facciano caos!
HTHcodice:<script type="text/javascript"> function back() { var web = []; web[0] = "background1.jpg"; web[1] = "background2.jpg"; web[2] = "background3.jpg"; web[3] = "background4.jpg"; var x = Math.floor( Math.random() * web.length); var mydiv = document.getElementById("innerpages"); var img = "images/"+web[x]; mydiv.style.background = "url(\"" + img + "\") no-repeat"; setTimeout( back , 5000 ); } </script>
Zappa