18th May 2008
Display a flash/image/text file randomly using javascript
The following javascript snippet will get the name of a random file from a list of files specified.
<script type="text/javascript">
//name of files
filenames = [ "filename1.gif", "filename2.gif", "filename3.gif", "filename4.gif" ];
//get a random entry from an array of filenames
var filename = filenames[Math.floor(Math.random()*filenames.length)];
//display filename here
document.write("path/to/file" + filename);
</script>
Technorati Tags: javascript, snippet



Leave a Reply