0

I have several links on the same page, and what I want is that every page load, different links and text will appear each time in order.

The code is:

<body>
<div id="RotateLink"></div>


<script language="javascript">
var links = new Array("link1", "link2", "link3", "link4", "link5");
var randomnumber=Math.floor(Math.random()*5)
document.getElementById("RotateLink").innerHTML = links[randomnumber];
</script>
</body>

Here is an image of what i want.

First page load/visitor: http://i.imgur.com/ziZ9JIO.png

Second visitor: http://i.imgur.com/himvsjV.png

And so on.

It will keep rotating in order.

How do I accomplish this?

Thank you.

User345
  • 11
  • 3
  • 1
    What, if anything, does this have to do with PHP? If you're using PHP, rotate the links there, not in the JS. If you're not using PHP, don't tag the question with PHP. – Mike May 04 '15 at 23:51

1 Answers1

1

Your code is almost complete. Just add the following shuffle instead of your single random number:

How can I shuffle an array?

If you want to keep the order just use

var newArray = [];
for(var i=0; i<a.length;i++)
   newArray.push(a[(randomNumber + i)%a.length]);
Community
  • 1
  • 1