I am looking to add a random image to a webpage. I would like it to beable to pull a image from a folder that could contain any file name.jpg even .gif also. I found this comment on here but no code or further post about it
see site at wichitarcraceway it the pictures on front page that iam dealing with.
A better idea would be to:
1. have a folder that contained the images.
2. a routine to get the number of items in the folder.
3. generate a random number based on the number of items.
4. get the Nth(random item) file in the folder.
5. verify that its an image file (if not get another one or the next on n+1)
6. pass the path and item name to the display routine.
7. the display routine also needs to size the image.
then you could just add new images to the folder and not have to rewrite the script each time.
any help would be great
Heres another I tried to use but renaming the files is not very productive. The problem is that the images are in a differant folder than the webpage, images/random maybe someone could help with this also
<script language="JavaScript">
<!--
/*
Random Image Script- By JavaScript Kit (http://www.javascriptkit.com)
Over 400+ free JavaScripts here!
Keep this notice intact please
*/
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.jpg"
myimages[2]="image2.jpg"
myimages[3]="image3.jpg"
myimages[4]="image4.jpg"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
*/I tried <img src="../image/random/'
*/<img src="../image/random"'
*/<img src="image/random"'
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>



Reply With Quote



Bookmarks