jelm
jelm

Reputation: 39

Random image url when reload

What I want is that the URL to some specific images should change on reload / new visit.

No news but this is how it looks today...

<li><a href="http://nameToSite/images/bkg1.jpg"></a></li>

Is it possible to make a jQuery url change

To something like

<li><a href="http://nameToSite/images/randomImages[1].jpg"></a></li> ?

thanks, great forum!

Upvotes: 1

Views: 620

Answers (2)

Adam
Adam

Reputation: 44939

The code below will change the link to point to randomImages[1] to randomImages[10] randomly each time it is run.

HTML:

<li><a id="link" href="http://nameToSite/images/randomImages[1].jpg"></a></li>

JQuery:

var randomnumber = Math.floor(Math.random()*10) + 1
$("#link").attr('href','http://nameToSite/images/randomImages[' + randomnumber + '].jpg');

Upvotes: 4

grossmae
grossmae

Reputation: 341

Just use jquery to request the server for an image. Have a servlet generate a random image URI and respond with it.

Or you could just use simple java script to choose a random image URI from a list onPageLoad.

Upvotes: 0

Related Questions