![]() |
|
|
|
|
|||||||
| Javascript / Java Applets Are you a JavaScript guy? Do you need help with JavaScript? This is the place to talk about anything related to Java. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need from a simple code on JavaScript with which can randomly change pictures on my website. My site is small and I don`t want to install any complicated content management system. I want only a little code to work.
|
|
#2
|
|||
|
|||
|
This is the most elementary code for this purpose.
HTML Code:
<html> <head> <script type="text/javascript"> var images = new Array(); images[1] = "image1.jpg"; images[2] = "image2.jpg"; images[3] = "image3.jpg"; images[4] = "image4.jpg"; images[5] = "picimage5.jpg"; function randomImage() { var i = Math.floor(Math.random()*images.length); document.images['randomImage'].src=images[i]; } </script> </head> <body onload="randomImage()"> <img name="randomImage" alt=""> </body> </html> |
|
#3
|
|||
|
|||
|
Quote:
That's pretty useful, thanks.
|
![]() |
| Tags |
| pictures, random |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|