Web Development Blog

by Ei Sabai Nyo

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: ,

Love what you've just read? Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
Your name:   Your email:  

4 Responses to “Display a flash/image/text file randomly using javascript”

  1. Jeevan says:

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

  2. IP Counter says:

    Hab ihn gelesen und finde Ihn sehr hilfreich Danke nochmal :-)

    http://www.ipcounter.net/

  3. enuotiz says:

    it’s not working for text file

Profile PicHello! 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 about me or have a look at some of the tips & resources I've written.
Subscribe to our newsletter to receive tips, resources and special offers related to web development & design.
We do NOT spam.
Your name:  
Your email:  

Tips & Resources

Tips & Resources
WordPress Web Hosting
Recommended web hosting providers for WordPress 3.0
iPhone Native App Development
Important steps into iPhone app development for beginners
iPhone Web App Development
Tips for iPhone web app development
Coupons for Web Developers
Get discounts on web hosting, domain names, templates, etc
10 Useful jQuery Snippets
Easy-to-use jQuery snippets for any website
HTML Email Newsletter
Step-by-step tutorial on how to code an HTML email newsletter
  • bluehost Hosting $6.95/month
  • Joomla Templates

Recommended Book

Categories