Javascript: url containing random number

A friend links my page to his site. Since I want users to avoid caching when visiting my page, I want the URL to have the following form:

http://www.mypage.com/index.php?456646556

Where 456646556 is a random number.

As my friend did not install php, how can I build a link with a random number using Javascript?

And my friend asked me to give him only the URL, without any additional features, since his page was already loaded by them. It can be done?

Thank you so much

+5
source share
4 answers

, :

var url = "http://www.mypage.com/index.php?rnd="+Math.random()

var url = "http://www.mypage.com/index.php?rnd="+new Date().getTime()

<a href="http://www.mypage.com/index.php?rnd=1" onClick="this.href=this.href.split('?')[0]+'?rnd='+new Date().getTime()">Mostly random</a>

, - , , getTime, , :

var rnd = new Date().getTime();
for (var i=0;i<links.length;i++) {
   links[i].href = "http://www.mypage.com/index.php?rnd="+(rnd+i);
}
+13
var lower = 0;
var upper = 100000000;
var url = "http://www.mypage.com/index.php?"+(Math.floor(Math.random()*(upper-lower))+lower)

X 0 () 100000000 (), ;)

+2
<a href="http://www.mypage.com/index.php?" onclick="this.href+=new Date().getTime();return true;">link</a>
+1

Math.random():

 // navigate to the new page and append a random number at the end of the url
 window.location.href = newUrl + '?' Math.random();

, Math.random, .

0

All Articles