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

  1. i checked it and it’s working fine
    thanks a lot

  2. it’s not working for text file

Comments are closed.

Twitter
LinkedIn
YouTube
Instagram