18 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
Love what you've just read? Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
Other similar posts that you might be interested in:
- Display a download dialog for pdf in PHP
- 10 most useful Javascript snippets from snipplr
- Removing file extension via .htaccess
- 10 Website Optimisation Tips for Web 2.0 Websites
- Display thickbox on page load
- How to customise your Facebook Fan Page with FBML
- How to customise WordPress Admin Login page
Hello! Welcome to Web development blog! My name is Ei Sabai and on this blog, I write about web development, mobile app development, latest web technologies and the likes. Read more 


i checked it and it’s working fine
thanks a lot
test
Hab ihn gelesen und finde Ihn sehr hilfreich Danke nochmal :-)
http://www.ipcounter.net/
it’s not working for text file