Random String in Javascript
String((new Date()).getTime()).replace(/\D/gi,'')
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:
function rnd(){ return String((new Date()).getTime()).replace(/\D/gi,'') }
var url = '/stuff/url/?'+rnd(); // do ajax stuff...
Comments
Post a Comment
|
Trackbacks
- Random String in Javascript (Apr 21st, 2008)












