Web Design and Development Forums

Go Back   Webforumz.com > Blogs > spinal007

Welcome to Webforumz.com.
Register Now Register now!

Random String in Javascript

Posted Apr 21st, 2008 at 13:18 by spinal007
Code:
String((new Date()).getTime()).replace(/\D/gi,'')
That's the quick way to automatically generate a random text string in javascript - a new string every millisecond.

It's a shame that in a time of "Web 2.0" and advanced ajax-powered web interfaces we, developers, still have to deal with querky browser issues pretty much all the time - most of the in IE.

Sometimes IE caches responses in the HTTPRequest object when it shouldn't, so ajax developers frequently add random characters to the query string to get around this issue. This code helps you do just that with very little processing.

Of course, I don't want to type the same code over and over again so I took it further and turned it into a neat little function:
Code:
 function rnd(){ return String((new Date()).getTime()).replace(/\D/gi,'') }
...so all I have to do is...
Code:
 var url = '/stuff/url/?'+rnd();
// do ajax stuff...
Happy javascript'ing!

Total Comments 0

Comments

Post a Comment Post a Comment
Total Trackbacks 0

Trackbacks

Recent Blog Entries by spinal007


Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 09:11.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59