views:

36

answers:

2

Hi, 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"&gt;&lt;/a&gt;&lt;/li&gt;

Is it possible to make a jQuery url change

To something like

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

thanks, great forum!

A: 

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.

grossmae
+3  A: 

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"&gt;&lt;/a&gt;&lt;/li&gt;

JQuery:

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