Snippets

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>

[tags]javascript, snippet[/tags]

4 thoughts on “Display a flash/image/text file randomly using javascript

Comments are closed.

Career Guide for Software Developers